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 eth_hw_addr_inherit(dev, mdev);
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);
82 SET_NETDEV_DEV(dev, mdev->dev.parent);
83 ret = register_netdevice(dev);
89 printk(KERN_WARNING "%s: failed to add new netdevice!\n",
95 printk(KERN_DEBUG "%s: registered netdevice %s\n",
96 mdev->name, dev->name);
102 void hostap_remove_interface(struct net_device *dev, int rtnl_locked,
103 int remove_from_list)
105 struct hostap_interface *iface;
110 iface = netdev_priv(dev);
112 if (remove_from_list) {
113 list_del(&iface->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);
126 unregister_netdev(dev);
128 /* dev->destructor = free_netdev() will free the device data, including
129 * private data, when removing the device */
133 static inline int prism2_wds_special_addr(u8 *addr)
135 if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5])
142 int prism2_wds_add(local_info_t *local, u8 *remote_addr,
145 struct net_device *dev;
146 struct list_head *ptr;
147 struct hostap_interface *iface, *empty, *match;
149 empty = match = NULL;
150 read_lock_bh(&local->iface_lock);
151 list_for_each(ptr, &local->hostap_interfaces) {
152 iface = list_entry(ptr, struct hostap_interface, list);
153 if (iface->type != HOSTAP_INTERFACE_WDS)
156 if (prism2_wds_special_addr(iface->u.wds.remote_addr))
158 else if (ether_addr_equal(iface->u.wds.remote_addr, remote_addr)) {
163 if (!match && empty && !prism2_wds_special_addr(remote_addr)) {
164 /* take pre-allocated entry into use */
165 memcpy(empty->u.wds.remote_addr, remote_addr, ETH_ALEN);
166 read_unlock_bh(&local->iface_lock);
167 printk(KERN_DEBUG "%s: using pre-allocated WDS netdevice %s\n",
168 local->dev->name, empty->dev->name);
171 read_unlock_bh(&local->iface_lock);
173 if (!prism2_wds_special_addr(remote_addr)) {
176 hostap_add_sta(local->ap, remote_addr);
179 if (local->wds_connections >= local->wds_max_connections)
182 /* verify that there is room for wds# postfix in the interface name */
183 if (strlen(local->dev->name) >= IFNAMSIZ - 5) {
184 printk(KERN_DEBUG "'%s' too long base device name\n",
189 dev = hostap_add_interface(local, HOSTAP_INTERFACE_WDS, rtnl_locked,
190 local->ddev->name, "wds%d");
194 iface = netdev_priv(dev);
195 memcpy(iface->u.wds.remote_addr, remote_addr, ETH_ALEN);
197 local->wds_connections++;
203 int prism2_wds_del(local_info_t *local, u8 *remote_addr,
204 int rtnl_locked, int do_not_remove)
207 struct list_head *ptr;
208 struct hostap_interface *iface, *selected = NULL;
210 write_lock_irqsave(&local->iface_lock, flags);
211 list_for_each(ptr, &local->hostap_interfaces) {
212 iface = list_entry(ptr, struct hostap_interface, list);
213 if (iface->type != HOSTAP_INTERFACE_WDS)
216 if (ether_addr_equal(iface->u.wds.remote_addr, remote_addr)) {
221 if (selected && !do_not_remove)
222 list_del(&selected->list);
223 write_unlock_irqrestore(&local->iface_lock, flags);
227 eth_zero_addr(selected->u.wds.remote_addr);
229 hostap_remove_interface(selected->dev, rtnl_locked, 0);
230 local->wds_connections--;
234 return selected ? 0 : -ENODEV;
238 u16 hostap_tx_callback_register(local_info_t *local,
239 void (*func)(struct sk_buff *, int ok, void *),
243 struct hostap_tx_callback_info *entry;
245 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
252 spin_lock_irqsave(&local->lock, flags);
253 entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1;
254 entry->next = local->tx_callback;
255 local->tx_callback = entry;
256 spin_unlock_irqrestore(&local->lock, flags);
262 int hostap_tx_callback_unregister(local_info_t *local, u16 idx)
265 struct hostap_tx_callback_info *cb, *prev = NULL;
267 spin_lock_irqsave(&local->lock, flags);
268 cb = local->tx_callback;
269 while (cb != NULL && cb->idx != idx) {
275 local->tx_callback = cb->next;
277 prev->next = cb->next;
280 spin_unlock_irqrestore(&local->lock, flags);
286 /* val is in host byte order */
287 int hostap_set_word(struct net_device *dev, int rid, u16 val)
289 struct hostap_interface *iface;
290 __le16 tmp = cpu_to_le16(val);
291 iface = netdev_priv(dev);
292 return iface->local->func->set_rid(dev, rid, &tmp, 2);
296 int hostap_set_string(struct net_device *dev, int rid, const char *val)
298 struct hostap_interface *iface;
299 char buf[MAX_SSID_LEN + 2];
302 iface = netdev_priv(dev);
304 if (len > MAX_SSID_LEN)
306 memset(buf, 0, sizeof(buf));
307 buf[0] = len; /* little endian 16 bit word */
308 memcpy(buf + 2, val, len);
310 return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2);
314 u16 hostap_get_porttype(local_info_t *local)
316 if (local->iw_mode == IW_MODE_ADHOC && local->pseudo_adhoc)
317 return HFA384X_PORTTYPE_PSEUDO_IBSS;
318 if (local->iw_mode == IW_MODE_ADHOC)
319 return HFA384X_PORTTYPE_IBSS;
320 if (local->iw_mode == IW_MODE_INFRA)
321 return HFA384X_PORTTYPE_BSS;
322 if (local->iw_mode == IW_MODE_REPEAT)
323 return HFA384X_PORTTYPE_WDS;
324 if (local->iw_mode == IW_MODE_MONITOR)
325 return HFA384X_PORTTYPE_PSEUDO_IBSS;
326 return HFA384X_PORTTYPE_HOSTAP;
330 int hostap_set_encryption(local_info_t *local)
333 int i, keylen, len, idx;
334 char keybuf[WEP_KEY_LEN + 1];
335 enum { NONE, WEP, OTHER } encrypt_type;
337 idx = local->crypt_info.tx_keyidx;
338 if (local->crypt_info.crypt[idx] == NULL ||
339 local->crypt_info.crypt[idx]->ops == NULL)
341 else if (strcmp(local->crypt_info.crypt[idx]->ops->name, "WEP") == 0)
344 encrypt_type = OTHER;
346 if (local->func->get_rid(local->dev, HFA384X_RID_CNFWEPFLAGS, &val, 2,
348 printk(KERN_DEBUG "Could not read current WEP flags.\n");
354 if (encrypt_type != NONE || local->privacy_invoked)
355 val |= HFA384X_WEPFLAGS_PRIVACYINVOKED;
357 val &= ~HFA384X_WEPFLAGS_PRIVACYINVOKED;
359 if (local->open_wep || encrypt_type == NONE ||
360 ((local->ieee_802_1x || local->wpa) && local->host_decrypt))
361 val &= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
363 val |= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
365 if ((encrypt_type != NONE || local->privacy_invoked) &&
366 (encrypt_type == OTHER || local->host_encrypt))
367 val |= HFA384X_WEPFLAGS_HOSTENCRYPT;
369 val &= ~HFA384X_WEPFLAGS_HOSTENCRYPT;
370 if ((encrypt_type != NONE || local->privacy_invoked) &&
371 (encrypt_type == OTHER || local->host_decrypt))
372 val |= HFA384X_WEPFLAGS_HOSTDECRYPT;
374 val &= ~HFA384X_WEPFLAGS_HOSTDECRYPT;
376 if (val != old_val &&
377 hostap_set_word(local->dev, HFA384X_RID_CNFWEPFLAGS, val)) {
378 printk(KERN_DEBUG "Could not write new WEP flags (0x%x)\n",
383 if (encrypt_type != WEP)
386 /* 104-bit support seems to require that all the keys are set to the
388 keylen = 6; /* first 5 octets */
389 len = local->crypt_info.crypt[idx]->ops->get_key(keybuf, sizeof(keybuf), NULL,
390 local->crypt_info.crypt[idx]->priv);
391 if (idx >= 0 && idx < WEP_KEYS && len > 5)
392 keylen = WEP_KEY_LEN + 1; /* first 13 octets */
394 for (i = 0; i < WEP_KEYS; i++) {
395 memset(keybuf, 0, sizeof(keybuf));
396 if (local->crypt_info.crypt[i]) {
397 (void) local->crypt_info.crypt[i]->ops->get_key(
398 keybuf, sizeof(keybuf),
399 NULL, local->crypt_info.crypt[i]->priv);
401 if (local->func->set_rid(local->dev,
402 HFA384X_RID_CNFDEFAULTKEY0 + i,
404 printk(KERN_DEBUG "Could not set key %d (len=%d)\n",
409 if (hostap_set_word(local->dev, HFA384X_RID_CNFWEPDEFAULTKEYID, idx)) {
410 printk(KERN_DEBUG "Could not set default keyid %d\n", idx);
417 printk(KERN_DEBUG "%s: encryption setup failed\n", local->dev->name);
422 int hostap_set_antsel(local_info_t *local)
427 if (local->antsel_tx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
428 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
429 HFA386X_CR_TX_CONFIGURE,
431 val &= ~(BIT(2) | BIT(1));
432 switch (local->antsel_tx) {
433 case HOSTAP_ANTSEL_DIVERSITY:
436 case HOSTAP_ANTSEL_LOW:
438 case HOSTAP_ANTSEL_HIGH:
443 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
444 HFA386X_CR_TX_CONFIGURE, &val, NULL)) {
445 printk(KERN_INFO "%s: setting TX AntSel failed\n",
451 if (local->antsel_rx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
452 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
453 HFA386X_CR_RX_CONFIGURE,
455 val &= ~(BIT(1) | BIT(0));
456 switch (local->antsel_rx) {
457 case HOSTAP_ANTSEL_DIVERSITY:
459 case HOSTAP_ANTSEL_LOW:
462 case HOSTAP_ANTSEL_HIGH:
463 val |= BIT(0) | BIT(1);
467 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
468 HFA386X_CR_RX_CONFIGURE, &val, NULL)) {
469 printk(KERN_INFO "%s: setting RX AntSel failed\n",
479 int hostap_set_roaming(local_info_t *local)
483 switch (local->host_roaming) {
485 val = HFA384X_ROAMING_HOST;
488 val = HFA384X_ROAMING_DISABLED;
492 val = HFA384X_ROAMING_FIRMWARE;
496 return hostap_set_word(local->dev, HFA384X_RID_CNFROAMINGMODE, val);
500 int hostap_set_auth_algs(local_info_t *local)
502 int val = local->auth_algs;
503 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
504 * set to include both Open and Shared Key flags. It tries to use
505 * Shared Key authentication in that case even if WEP keys are not
506 * configured.. STA f/w v0.7.6 is able to handle such configuration,
507 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
508 if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) &&
509 val != PRISM2_AUTH_OPEN && val != PRISM2_AUTH_SHARED_KEY)
510 val = PRISM2_AUTH_OPEN;
512 if (hostap_set_word(local->dev, HFA384X_RID_CNFAUTHENTICATION, val)) {
513 printk(KERN_INFO "%s: cnfAuthentication setting to 0x%x "
514 "failed\n", local->dev->name, local->auth_algs);
522 void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
526 status = __le16_to_cpu(rx->status);
528 printk(KERN_DEBUG "%s: RX status=0x%04x (port=%d, type=%d, "
529 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
531 name, status, (status >> 8) & 0x07, status >> 13, status & 1,
532 rx->silence, rx->signal, rx->rate, rx->rxflow, jiffies);
534 fc = __le16_to_cpu(rx->frame_control);
535 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
537 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
538 (fc & IEEE80211_FCTL_STYPE) >> 4,
539 __le16_to_cpu(rx->duration_id), __le16_to_cpu(rx->seq_ctrl),
540 __le16_to_cpu(rx->data_len),
541 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
542 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
544 printk(KERN_DEBUG " A1=%pM A2=%pM A3=%pM A4=%pM\n",
545 rx->addr1, rx->addr2, rx->addr3, rx->addr4);
547 printk(KERN_DEBUG " dst=%pM src=%pM len=%d\n",
548 rx->dst_addr, rx->src_addr,
549 __be16_to_cpu(rx->len));
553 void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
557 printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d "
558 "tx_control=0x%04x; jiffies=%ld\n",
559 name, __le16_to_cpu(tx->status), tx->retry_count, tx->tx_rate,
560 __le16_to_cpu(tx->tx_control), jiffies);
562 fc = __le16_to_cpu(tx->frame_control);
563 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
565 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
566 (fc & IEEE80211_FCTL_STYPE) >> 4,
567 __le16_to_cpu(tx->duration_id), __le16_to_cpu(tx->seq_ctrl),
568 __le16_to_cpu(tx->data_len),
569 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
570 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
572 printk(KERN_DEBUG " A1=%pM A2=%pM A3=%pM A4=%pM\n",
573 tx->addr1, tx->addr2, tx->addr3, tx->addr4);
575 printk(KERN_DEBUG " dst=%pM src=%pM len=%d\n",
576 tx->dst_addr, tx->src_addr,
577 __be16_to_cpu(tx->len));
581 static int hostap_80211_header_parse(const struct sk_buff *skb,
582 unsigned char *haddr)
584 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
589 int hostap_80211_get_hdrlen(__le16 fc)
591 if (ieee80211_is_data(fc) && ieee80211_has_a4 (fc))
592 return 30; /* Addr4 */
593 else if (ieee80211_is_cts(fc) || ieee80211_is_ack(fc))
595 else if (ieee80211_is_ctl(fc))
602 static int prism2_close(struct net_device *dev)
604 struct hostap_interface *iface;
607 PDEBUG(DEBUG_FLOW, "%s: prism2_close\n", dev->name);
609 iface = netdev_priv(dev);
610 local = iface->local;
612 if (dev == local->ddev) {
613 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
615 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
616 if (!local->hostapd && dev == local->dev &&
617 (!local->func->card_present || local->func->card_present(local)) &&
618 local->hw_ready && local->ap && local->iw_mode == IW_MODE_MASTER)
619 hostap_deauth_all_stas(dev, local->ap, 1);
620 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
622 if (dev == local->dev) {
623 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
626 if (netif_running(dev)) {
627 netif_stop_queue(dev);
628 netif_device_detach(dev);
631 cancel_work_sync(&local->reset_queue);
632 cancel_work_sync(&local->set_multicast_list_queue);
633 cancel_work_sync(&local->set_tim_queue);
634 #ifndef PRISM2_NO_STATION_MODES
635 cancel_work_sync(&local->info_queue);
637 cancel_work_sync(&local->comms_qual_update);
639 module_put(local->hw_module);
641 local->num_dev_open--;
643 if (dev != local->dev && local->dev->flags & IFF_UP &&
644 local->master_dev_auto_open && local->num_dev_open == 1) {
645 /* Close master radio interface automatically if it was also
646 * opened automatically and we are now closing the last
647 * remaining non-master device. */
648 dev_close(local->dev);
655 static int prism2_open(struct net_device *dev)
657 struct hostap_interface *iface;
660 PDEBUG(DEBUG_FLOW, "%s: prism2_open\n", dev->name);
662 iface = netdev_priv(dev);
663 local = iface->local;
666 printk(KERN_DEBUG "%s: could not set interface UP - no PRI "
671 if ((local->func->card_present && !local->func->card_present(local)) ||
672 local->hw_downloading)
675 if (!try_module_get(local->hw_module))
677 local->num_dev_open++;
679 if (!local->dev_enabled && local->func->hw_enable(dev, 1)) {
680 printk(KERN_WARNING "%s: could not enable MAC port\n",
685 if (!local->dev_enabled)
686 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
687 local->dev_enabled = 1;
689 if (dev != local->dev && !(local->dev->flags & IFF_UP)) {
690 /* Master radio interface is needed for all operation, so open
691 * it automatically when any virtual net_device is opened. */
692 local->master_dev_auto_open = 1;
693 dev_open(local->dev);
696 netif_device_attach(dev);
697 netif_start_queue(dev);
703 static int prism2_set_mac_address(struct net_device *dev, void *p)
705 struct hostap_interface *iface;
707 struct list_head *ptr;
708 struct sockaddr *addr = p;
710 iface = netdev_priv(dev);
711 local = iface->local;
713 if (local->func->set_rid(dev, HFA384X_RID_CNFOWNMACADDR, addr->sa_data,
714 ETH_ALEN) < 0 || local->func->reset_port(dev))
717 read_lock_bh(&local->iface_lock);
718 list_for_each(ptr, &local->hostap_interfaces) {
719 iface = list_entry(ptr, struct hostap_interface, list);
720 memcpy(iface->dev->dev_addr, addr->sa_data, ETH_ALEN);
722 memcpy(local->dev->dev_addr, addr->sa_data, ETH_ALEN);
723 read_unlock_bh(&local->iface_lock);
729 /* TODO: to be further implemented as soon as Prism2 fully supports
730 * GroupAddresses and correct documentation is available */
731 void hostap_set_multicast_list_queue(struct work_struct *work)
733 local_info_t *local =
734 container_of(work, local_info_t, set_multicast_list_queue);
735 struct net_device *dev = local->dev;
737 if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
738 local->is_promisc)) {
739 printk(KERN_INFO "%s: %sabling promiscuous mode failed\n",
740 dev->name, local->is_promisc ? "en" : "dis");
745 static void hostap_set_multicast_list(struct net_device *dev)
748 /* FIX: promiscuous mode seems to be causing a lot of problems with
749 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
750 * corrupted incoming frames). This code is now commented out while the
751 * problems are investigated. */
752 struct hostap_interface *iface;
755 iface = netdev_priv(dev);
756 local = iface->local;
757 if ((dev->flags & IFF_ALLMULTI) || (dev->flags & IFF_PROMISC)) {
758 local->is_promisc = 1;
760 local->is_promisc = 0;
763 schedule_work(&local->set_multicast_list_queue);
768 static void prism2_tx_timeout(struct net_device *dev)
770 struct hostap_interface *iface;
772 struct hfa384x_regs regs;
774 iface = netdev_priv(dev);
775 local = iface->local;
777 printk(KERN_WARNING "%s Tx timed out! Resetting card\n", dev->name);
778 netif_stop_queue(local->dev);
780 local->func->read_regs(dev, ®s);
781 printk(KERN_DEBUG "%s: CMD=%04x EVSTAT=%04x "
782 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
783 dev->name, regs.cmd, regs.evstat, regs.offset0, regs.offset1,
786 local->func->schedule_reset(local);
789 const struct header_ops hostap_80211_ops = {
790 .create = eth_header,
791 .cache = eth_header_cache,
792 .cache_update = eth_header_cache_update,
793 .parse = hostap_80211_header_parse,
795 EXPORT_SYMBOL(hostap_80211_ops);
798 static const struct net_device_ops hostap_netdev_ops = {
799 .ndo_start_xmit = hostap_data_start_xmit,
801 .ndo_open = prism2_open,
802 .ndo_stop = prism2_close,
803 .ndo_do_ioctl = hostap_ioctl,
804 .ndo_set_mac_address = prism2_set_mac_address,
805 .ndo_set_rx_mode = hostap_set_multicast_list,
806 .ndo_tx_timeout = prism2_tx_timeout,
807 .ndo_validate_addr = eth_validate_addr,
810 static const struct net_device_ops hostap_mgmt_netdev_ops = {
811 .ndo_start_xmit = hostap_mgmt_start_xmit,
813 .ndo_open = prism2_open,
814 .ndo_stop = prism2_close,
815 .ndo_do_ioctl = hostap_ioctl,
816 .ndo_set_mac_address = prism2_set_mac_address,
817 .ndo_set_rx_mode = hostap_set_multicast_list,
818 .ndo_tx_timeout = prism2_tx_timeout,
819 .ndo_validate_addr = eth_validate_addr,
822 static const struct net_device_ops hostap_master_ops = {
823 .ndo_start_xmit = hostap_master_start_xmit,
825 .ndo_open = prism2_open,
826 .ndo_stop = prism2_close,
827 .ndo_do_ioctl = hostap_ioctl,
828 .ndo_set_mac_address = prism2_set_mac_address,
829 .ndo_set_rx_mode = hostap_set_multicast_list,
830 .ndo_tx_timeout = prism2_tx_timeout,
831 .ndo_validate_addr = eth_validate_addr,
834 void hostap_setup_dev(struct net_device *dev, local_info_t *local,
837 struct hostap_interface *iface;
839 iface = netdev_priv(dev);
841 dev->min_mtu = PRISM2_MIN_MTU;
842 dev->max_mtu = PRISM2_MAX_MTU;
843 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
845 /* kernel callbacks */
847 /* Currently, we point to the proper spy_data only on
848 * the main_dev. This could be fixed. Jean II */
849 iface->wireless_data.spy_data = &iface->spy_data;
850 dev->wireless_data = &iface->wireless_data;
852 dev->wireless_handlers = &hostap_iw_handler_def;
853 dev->watchdog_timeo = TX_TIMEOUT;
856 case HOSTAP_INTERFACE_AP:
857 dev->priv_flags |= IFF_NO_QUEUE; /* use main radio device queue */
858 dev->netdev_ops = &hostap_mgmt_netdev_ops;
859 dev->type = ARPHRD_IEEE80211;
860 dev->header_ops = &hostap_80211_ops;
862 case HOSTAP_INTERFACE_MASTER:
863 dev->netdev_ops = &hostap_master_ops;
866 dev->priv_flags |= IFF_NO_QUEUE; /* use main radio device queue */
867 dev->netdev_ops = &hostap_netdev_ops;
870 dev->mtu = local->mtu;
873 dev->ethtool_ops = &prism2_ethtool_ops;
877 static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
879 struct net_device *dev = local->dev;
884 printk(KERN_DEBUG "%s: enabling hostapd mode\n", dev->name);
886 local->apdev = hostap_add_interface(local, HOSTAP_INTERFACE_AP,
887 rtnl_locked, local->ddev->name,
889 if (local->apdev == NULL)
896 static int hostap_disable_hostapd(local_info_t *local, int rtnl_locked)
898 struct net_device *dev = local->dev;
900 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
902 hostap_remove_interface(local->apdev, rtnl_locked, 1);
909 static int hostap_enable_hostapd_sta(local_info_t *local, int rtnl_locked)
911 struct net_device *dev = local->dev;
916 printk(KERN_DEBUG "%s: enabling hostapd STA mode\n", dev->name);
918 local->stadev = hostap_add_interface(local, HOSTAP_INTERFACE_STA,
919 rtnl_locked, local->ddev->name,
921 if (local->stadev == NULL)
928 static int hostap_disable_hostapd_sta(local_info_t *local, int rtnl_locked)
930 struct net_device *dev = local->dev;
932 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
934 hostap_remove_interface(local->stadev, rtnl_locked, 1);
935 local->stadev = NULL;
941 int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked)
945 if (val < 0 || val > 1)
948 if (local->hostapd == val)
952 ret = hostap_enable_hostapd(local, rtnl_locked);
957 ret = hostap_disable_hostapd(local, rtnl_locked);
966 int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked)
970 if (val < 0 || val > 1)
973 if (local->hostapd_sta == val)
977 ret = hostap_enable_hostapd_sta(local, rtnl_locked);
979 local->hostapd_sta = 1;
981 local->hostapd_sta = 0;
982 ret = hostap_disable_hostapd_sta(local, rtnl_locked);
984 local->hostapd_sta = 1;
992 int prism2_update_comms_qual(struct net_device *dev)
994 struct hostap_interface *iface;
997 struct hfa384x_comms_quality sq;
999 iface = netdev_priv(dev);
1000 local = iface->local;
1001 if (!local->sta_fw_ver)
1003 else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1004 if (local->func->get_rid(local->dev,
1005 HFA384X_RID_DBMCOMMSQUALITY,
1006 &sq, sizeof(sq), 1) >= 0) {
1007 local->comms_qual = (s16) le16_to_cpu(sq.comm_qual);
1008 local->avg_signal = (s16) le16_to_cpu(sq.signal_level);
1009 local->avg_noise = (s16) le16_to_cpu(sq.noise_level);
1010 local->last_comms_qual_update = jiffies;
1014 if (local->func->get_rid(local->dev, HFA384X_RID_COMMSQUALITY,
1015 &sq, sizeof(sq), 1) >= 0) {
1016 local->comms_qual = le16_to_cpu(sq.comm_qual);
1017 local->avg_signal = HFA384X_LEVEL_TO_dBm(
1018 le16_to_cpu(sq.signal_level));
1019 local->avg_noise = HFA384X_LEVEL_TO_dBm(
1020 le16_to_cpu(sq.noise_level));
1021 local->last_comms_qual_update = jiffies;
1030 int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u16 stype,
1031 u8 *body, size_t bodylen)
1033 struct sk_buff *skb;
1034 struct hostap_ieee80211_mgmt *mgmt;
1035 struct hostap_skb_tx_data *meta;
1036 struct net_device *dev = local->dev;
1038 skb = dev_alloc_skb(IEEE80211_MGMT_HDR_LEN + bodylen);
1042 mgmt = (struct hostap_ieee80211_mgmt *)
1043 skb_put(skb, IEEE80211_MGMT_HDR_LEN);
1044 memset(mgmt, 0, IEEE80211_MGMT_HDR_LEN);
1045 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
1046 memcpy(mgmt->da, dst, ETH_ALEN);
1047 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1048 memcpy(mgmt->bssid, dst, ETH_ALEN);
1050 memcpy(skb_put(skb, bodylen), body, bodylen);
1052 meta = (struct hostap_skb_tx_data *) skb->cb;
1053 memset(meta, 0, sizeof(*meta));
1054 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1055 meta->iface = netdev_priv(dev);
1058 skb_reset_mac_header(skb);
1059 skb_reset_network_header(skb);
1060 dev_queue_xmit(skb);
1066 int prism2_sta_deauth(local_info_t *local, u16 reason)
1068 union iwreq_data wrqu;
1070 __le16 val = cpu_to_le16(reason);
1072 if (local->iw_mode != IW_MODE_INFRA ||
1073 is_zero_ether_addr(local->bssid) ||
1074 ether_addr_equal(local->bssid, "\x44\x44\x44\x44\x44\x44"))
1077 ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,
1079 eth_zero_addr(wrqu.ap_addr.sa_data);
1080 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
1085 struct proc_dir_entry *hostap_proc;
1087 static int __init hostap_init(void)
1089 if (init_net.proc_net != NULL) {
1090 hostap_proc = proc_mkdir("hostap", init_net.proc_net);
1092 printk(KERN_WARNING "Failed to mkdir "
1093 "/proc/net/hostap\n");
1101 static void __exit hostap_exit(void)
1103 if (hostap_proc != NULL) {
1105 remove_proc_entry("hostap", init_net.proc_net);
1110 EXPORT_SYMBOL(hostap_set_word);
1111 EXPORT_SYMBOL(hostap_set_string);
1112 EXPORT_SYMBOL(hostap_get_porttype);
1113 EXPORT_SYMBOL(hostap_set_encryption);
1114 EXPORT_SYMBOL(hostap_set_antsel);
1115 EXPORT_SYMBOL(hostap_set_roaming);
1116 EXPORT_SYMBOL(hostap_set_auth_algs);
1117 EXPORT_SYMBOL(hostap_dump_rx_header);
1118 EXPORT_SYMBOL(hostap_dump_tx_header);
1119 EXPORT_SYMBOL(hostap_80211_get_hdrlen);
1120 EXPORT_SYMBOL(hostap_setup_dev);
1121 EXPORT_SYMBOL(hostap_set_multicast_list_queue);
1122 EXPORT_SYMBOL(hostap_set_hostapd);
1123 EXPORT_SYMBOL(hostap_set_hostapd_sta);
1124 EXPORT_SYMBOL(hostap_add_interface);
1125 EXPORT_SYMBOL(hostap_remove_interface);
1126 EXPORT_SYMBOL(prism2_update_comms_qual);
1128 module_init(hostap_init);
1129 module_exit(hostap_exit);