1 /* src/p80211/p80211knetdev.c
3 * Linux Kernel net device interface
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
47 * The functions required for a Linux network device are defined here.
49 * --------------------------------------------------------------------
53 /*================================================================*/
57 #include <linux/version.h>
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
62 #include <linux/types.h>
63 #include <linux/skbuff.h>
64 #include <linux/slab.h>
65 #include <linux/proc_fs.h>
66 #include <linux/interrupt.h>
67 #include <linux/netdevice.h>
68 #include <linux/kmod.h>
69 #include <linux/if_arp.h>
70 #include <linux/wireless.h>
71 #include <linux/sockios.h>
72 #include <linux/etherdevice.h>
73 #include <linux/if_ether.h>
74 #include <linux/byteorder/generic.h>
76 #include <asm/bitops.h>
77 #include <asm/uaccess.h>
78 #include <asm/byteorder.h>
81 #include <linux/ethtool.h>
84 #include <net/iw_handler.h>
85 #include <net/net_namespace.h>
87 /*================================================================*/
88 /* Project Includes */
90 #include "wlan_compat.h"
91 #include "p80211types.h"
92 #include "p80211hdr.h"
93 #include "p80211conv.h"
94 #include "p80211mgmt.h"
95 #include "p80211msg.h"
96 #include "p80211netdev.h"
97 #include "p80211ioctl.h"
98 #include "p80211req.h"
99 #include "p80211metastruct.h"
100 #include "p80211metadef.h"
102 /*================================================================*/
103 /* Local Constants */
105 /*================================================================*/
109 /*================================================================*/
112 /*================================================================*/
113 /* Local Function Declarations */
115 /* Support functions */
116 static void p80211netdev_rx_bh(unsigned long arg);
118 /* netdevice method functions */
119 static int p80211knetdev_init( netdevice_t *netdev);
120 static struct net_device_stats* p80211knetdev_get_stats(netdevice_t *netdev);
121 static int p80211knetdev_open( netdevice_t *netdev);
122 static int p80211knetdev_stop( netdevice_t *netdev );
123 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev);
124 static void p80211knetdev_set_multicast_list(netdevice_t *dev);
125 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd);
126 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr);
127 static void p80211knetdev_tx_timeout(netdevice_t *netdev);
128 static int p80211_rx_typedrop( wlandevice_t *wlandev, u16 fc);
130 int wlan_watchdog = 5000;
131 module_param(wlan_watchdog, int, 0644);
132 MODULE_PARM_DESC(wlan_watchdog, "transmit timeout in milliseconds");
134 int wlan_wext_write = 1;
135 module_param(wlan_wext_write, int, 0644);
136 MODULE_PARM_DESC(wlan_wext_write, "enable write wireless extensions");
138 #ifdef WLAN_INCLUDE_DEBUG
140 module_param(wlan_debug, int, 0644);
141 MODULE_PARM_DESC(wlan_debug, "p80211 debug level");
144 /*================================================================*/
145 /* Function Definitions */
147 /*----------------------------------------------------------------
150 * Init method for a Linux netdevice. Called in response to
158 ----------------------------------------------------------------*/
159 static int p80211knetdev_init( netdevice_t *netdev)
161 /* Called in response to register_netdev */
162 /* This is usually the probe function, but the probe has */
163 /* already been done by the MSD and the create_kdev */
164 /* function. All we do here is return success */
169 /*----------------------------------------------------------------
170 * p80211knetdev_get_stats
172 * Statistics retrieval for linux netdevices. Here we're reporting
173 * the Linux i/f level statistics. Hence, for the primary numbers,
174 * we don't want to report the numbers from the MIB. Eventually,
175 * it might be useful to collect some of the error counters though.
178 * netdev Linux netdevice
181 * the address of the statistics structure
182 ----------------------------------------------------------------*/
183 static struct net_device_stats*
184 p80211knetdev_get_stats(netdevice_t *netdev)
186 wlandevice_t *wlandev = netdev->ml_priv;
188 /* TODO: review the MIB stats for items that correspond to
191 return &(wlandev->linux_stats);
195 /*----------------------------------------------------------------
198 * Linux netdevice open method. Following a successful call here,
199 * the device is supposed to be ready for tx and rx. In our
200 * situation that may not be entirely true due to the state of the
204 * netdev Linux network device structure
207 * zero on success, non-zero otherwise
208 ----------------------------------------------------------------*/
209 static int p80211knetdev_open( netdevice_t *netdev )
211 int result = 0; /* success */
212 wlandevice_t *wlandev = netdev->ml_priv;
214 /* Check to make sure the MSD is running */
215 if ( wlandev->msdstate != WLAN_MSD_RUNNING ) {
219 /* Tell the MSD to open */
220 if ( wlandev->open != NULL) {
221 result = wlandev->open(wlandev);
223 netif_start_queue(wlandev->netdev);
224 wlandev->state = WLAN_DEVICE_OPEN;
234 /*----------------------------------------------------------------
237 * Linux netdevice stop (close) method. Following this call,
238 * no frames should go up or down through this interface.
241 * netdev Linux network device structure
244 * zero on success, non-zero otherwise
245 ----------------------------------------------------------------*/
246 static int p80211knetdev_stop( netdevice_t *netdev )
249 wlandevice_t *wlandev = netdev->ml_priv;
251 if ( wlandev->close != NULL ) {
252 result = wlandev->close(wlandev);
255 netif_stop_queue(wlandev->netdev);
256 wlandev->state = WLAN_DEVICE_CLOSED;
261 /*----------------------------------------------------------------
264 * Frame receive function called by the mac specific driver.
267 * wlandev WLAN network device structure
268 * skb skbuff containing a full 802.11 frame.
273 ----------------------------------------------------------------*/
275 p80211netdev_rx(wlandevice_t *wlandev, struct sk_buff *skb )
277 /* Enqueue for post-irq processing */
278 skb_queue_tail(&wlandev->nsd_rxq, skb);
280 tasklet_schedule(&wlandev->rx_bh);
285 /*----------------------------------------------------------------
288 * Deferred processing of all received frames.
291 * wlandev WLAN network device structure
292 * skb skbuff containing a full 802.11 frame.
297 ----------------------------------------------------------------*/
298 static void p80211netdev_rx_bh(unsigned long arg)
300 wlandevice_t *wlandev = (wlandevice_t *) arg;
301 struct sk_buff *skb = NULL;
302 netdevice_t *dev = wlandev->netdev;
303 p80211_hdr_a3_t *hdr;
306 /* Let's empty our our queue */
307 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
308 if (wlandev->state == WLAN_DEVICE_OPEN) {
310 if (dev->type != ARPHRD_ETHER) {
311 /* RAW frame; we shouldn't convert it */
312 // XXX Append the Prism Header here instead.
314 /* set up various data fields */
316 skb_reset_mac_header(skb);
317 skb->ip_summed = CHECKSUM_NONE;
318 skb->pkt_type = PACKET_OTHERHOST;
319 skb->protocol = htons(ETH_P_80211_RAW);
320 dev->last_rx = jiffies;
322 wlandev->linux_stats.rx_packets++;
323 wlandev->linux_stats.rx_bytes += skb->len;
327 hdr = (p80211_hdr_a3_t *)skb->data;
328 fc = le16_to_cpu(hdr->fc);
329 if (p80211_rx_typedrop(wlandev, fc)) {
334 /* perform mcast filtering */
335 if (wlandev->netdev->flags & IFF_ALLMULTI) {
336 /* allow my local address through */
337 if (memcmp(hdr->a1, wlandev->netdev->dev_addr, ETH_ALEN) != 0) {
338 /* but reject anything else that isn't multicast */
339 if (!(hdr->a1[0] & 0x01)) {
346 if ( skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0 ) {
347 skb->dev->last_rx = jiffies;
348 wlandev->linux_stats.rx_packets++;
349 wlandev->linux_stats.rx_bytes += skb->len;
353 WLAN_LOG_DEBUG(1, "p80211_to_ether failed.\n");
361 /*----------------------------------------------------------------
362 * p80211knetdev_hard_start_xmit
364 * Linux netdevice method for transmitting a frame.
367 * skb Linux sk_buff containing the frame.
368 * netdev Linux netdevice.
371 * If the lower layers report that buffers are full. netdev->tbusy
372 * will be set to prevent higher layers from sending more traffic.
374 * Note: If this function returns non-zero, higher layers retain
375 * ownership of the skb.
378 * zero on success, non-zero on failure.
379 ----------------------------------------------------------------*/
380 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev)
384 wlandevice_t *wlandev = netdev->ml_priv;
385 p80211_hdr_t p80211_hdr;
386 p80211_metawep_t p80211_wep;
392 if (wlandev->state != WLAN_DEVICE_OPEN) {
397 memset(&p80211_hdr, 0, sizeof(p80211_hdr_t));
398 memset(&p80211_wep, 0, sizeof(p80211_metawep_t));
400 if ( netif_queue_stopped(netdev) ) {
401 WLAN_LOG_DEBUG(1, "called when queue stopped.\n");
406 netif_stop_queue(netdev);
408 /* Check to see that a valid mode is set */
409 switch( wlandev->macmode ) {
410 case WLAN_MACMODE_IBSS_STA:
411 case WLAN_MACMODE_ESS_STA:
412 case WLAN_MACMODE_ESS_AP:
415 /* Mode isn't set yet, just drop the frame
416 * and return success .
417 * TODO: we need a saner way to handle this
419 if(skb->protocol != ETH_P_80211_RAW) {
420 netif_start_queue(wlandev->netdev);
422 "Tx attempt prior to association, frame dropped.\n");
423 wlandev->linux_stats.tx_dropped++;
430 /* Check for raw transmits */
431 if(skb->protocol == ETH_P_80211_RAW) {
432 if (!capable(CAP_NET_ADMIN)) {
436 /* move the header over */
437 memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));
438 skb_pull(skb, sizeof(p80211_hdr_t));
440 if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {
442 WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n",
448 if ( wlandev->txframe == NULL ) {
453 netdev->trans_start = jiffies;
455 wlandev->linux_stats.tx_packets++;
456 /* count only the packet payload */
457 wlandev->linux_stats.tx_bytes += skb->len;
459 txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);
461 if ( txresult == 0) {
462 /* success and more buf */
463 /* avail, re: hw_txdata */
464 netif_wake_queue(wlandev->netdev);
466 } else if ( txresult == 1 ) {
467 /* success, no more avail */
468 WLAN_LOG_DEBUG(3, "txframe success, no more bufs\n");
469 /* netdev->tbusy = 1; don't set here, irqhdlr */
470 /* may have already cleared it */
472 } else if ( txresult == 2 ) {
473 /* alloc failure, drop frame */
474 WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");
477 /* buffer full or queue busy, drop frame. */
478 WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");
483 /* Free up the WEP buffer if it's not the same as the skb */
484 if ((p80211_wep.data) && (p80211_wep.data != skb->data))
485 kfree(p80211_wep.data);
487 /* we always free the skb here, never in a lower level. */
495 /*----------------------------------------------------------------
496 * p80211knetdev_set_multicast_list
498 * Called from higher lavers whenever there's a need to set/clear
499 * promiscuous mode or rewrite the multicast list.
506 ----------------------------------------------------------------*/
507 static void p80211knetdev_set_multicast_list(netdevice_t *dev)
509 wlandevice_t *wlandev = dev->ml_priv;
511 /* TODO: real multicast support as well */
513 if (wlandev->set_multicast_list)
514 wlandev->set_multicast_list(wlandev, dev);
520 static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
523 struct ethtool_drvinfo info;
524 struct ethtool_value edata;
526 memset(&info, 0, sizeof(info));
527 memset(&edata, 0, sizeof(edata));
529 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
533 case ETHTOOL_GDRVINFO:
535 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
537 snprintf(info.version, sizeof(info.version), "%s",
543 if (copy_to_user(useraddr, &info, sizeof(info)))
550 if (wlandev->linkstatus &&
551 (wlandev->macmode != WLAN_MACMODE_NONE)) {
557 if (copy_to_user(useraddr, &edata, sizeof(edata)))
568 /*----------------------------------------------------------------
569 * p80211knetdev_do_ioctl
571 * Handle an ioctl call on one of our devices. Everything Linux
572 * ioctl specific is done here. Then we pass the contents of the
573 * ifr->data to the request message handler.
576 * dev Linux kernel netdevice
577 * ifr Our private ioctl request structure, typed for the
578 * generic struct ifreq so we can use ptr to func
582 * zero on success, a negative errno on failure. Possible values:
583 * -ENETDOWN Device isn't up.
584 * -EBUSY cmd already in progress
585 * -ETIME p80211 cmd timed out (MSD may have its own timers)
586 * -EFAULT memory fault copying msg from user buffer
587 * -ENOMEM unable to allocate kernel msg buffer
588 * -ENOSYS bad magic, it the cmd really for us?
589 * -EintR sleeping on cmd, awakened by signal, cmd cancelled.
592 * Process thread (ioctl caller). TODO: SMP support may require
594 ----------------------------------------------------------------*/
595 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd)
598 p80211ioctl_req_t *req = (p80211ioctl_req_t*)ifr;
599 wlandevice_t *wlandev = dev->ml_priv;
602 WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
605 if (cmd == SIOCETHTOOL) {
606 result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);
611 /* Test the magic, assume ifr is good if it's there */
612 if ( req->magic != P80211_IOCTL_MAGIC ) {
617 if ( cmd == P80211_IFTEST ) {
620 } else if ( cmd != P80211_IFREQ ) {
625 /* Allocate a buf of size req->len */
626 if ((msgbuf = kmalloc( req->len, GFP_KERNEL))) {
627 if ( copy_from_user( msgbuf, (void __user *) req->data, req->len) ) {
630 result = p80211req_dorequest( wlandev, msgbuf);
634 if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {
643 return result; /* If allocate,copyfrom or copyto fails, return errno */
646 /*----------------------------------------------------------------
647 * p80211knetdev_set_mac_address
649 * Handles the ioctl for changing the MACAddress of a netdevice
651 * references: linux/netdevice.h and drivers/net/net_init.c
653 * NOTE: [MSM] We only prevent address changes when the netdev is
654 * up. We don't control anything based on dot11 state. If the
655 * address is changed on a STA that's currently associated, you
656 * will probably lose the ability to send and receive data frames.
657 * Just be aware. Therefore, this should usually only be done
658 * prior to scan/join/auth/assoc.
661 * dev netdevice struct
662 * addr the new MACAddress (a struct)
665 * zero on success, a negative errno on failure. Possible values:
666 * -EBUSY device is bussy (cmd not possible)
667 * -and errors returned by: p80211req_dorequest(..)
669 * by: Collin R. Mulliner <collin@mulliner.org>
670 ----------------------------------------------------------------*/
671 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr)
673 struct sockaddr *new_addr = addr;
674 p80211msg_dot11req_mibset_t dot11req;
675 p80211item_unk392_t *mibattr;
676 p80211item_pstr6_t *macaddr;
677 p80211item_uint32_t *resultcode;
680 /* If we're running, we don't allow MAC address changes */
681 if (netif_running(dev)) {
685 /* Set up some convenience pointers. */
686 mibattr = &dot11req.mibattribute;
687 macaddr = (p80211item_pstr6_t*)&mibattr->data;
688 resultcode = &dot11req.resultcode;
690 /* Set up a dot11req_mibset */
691 memset(&dot11req, 0, sizeof(p80211msg_dot11req_mibset_t));
692 dot11req.msgcode = DIDmsg_dot11req_mibset;
693 dot11req.msglen = sizeof(p80211msg_dot11req_mibset_t);
694 memcpy(dot11req.devname,
695 ((wlandevice_t *)dev->ml_priv)->name,
696 WLAN_DEVNAMELEN_MAX - 1);
698 /* Set up the mibattribute argument */
699 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
700 mibattr->status = P80211ENUM_msgitem_status_data_ok;
701 mibattr->len = sizeof(mibattr->data);
703 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;
704 macaddr->status = P80211ENUM_msgitem_status_data_ok;
705 macaddr->len = sizeof(macaddr->data);
706 macaddr->data.len = ETH_ALEN;
707 memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN);
709 /* Set up the resultcode argument */
710 resultcode->did = DIDmsg_dot11req_mibset_resultcode;
711 resultcode->status = P80211ENUM_msgitem_status_no_value;
712 resultcode->len = sizeof(resultcode->data);
713 resultcode->data = 0;
715 /* now fire the request */
716 result = p80211req_dorequest(dev->ml_priv, (u8 *)&dot11req);
718 /* If the request wasn't successful, report an error and don't
719 * change the netdev address
721 if ( result != 0 || resultcode->data != P80211ENUM_resultcode_success) {
723 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
724 result = -EADDRNOTAVAIL;
726 /* everything's ok, change the addr in netdev */
727 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
733 static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
735 // 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
736 // and another 8 for wep.
737 if ( (new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))
747 /*----------------------------------------------------------------
750 * Roughly matches the functionality of ether_setup. Here
751 * we set up any members of the wlandevice structure that are common
752 * to all devices. Additionally, we allocate a linux 'struct device'
753 * and perform the same setup as ether_setup.
755 * Note: It's important that the caller have setup the wlandev->name
756 * ptr prior to calling this function.
759 * wlandev ptr to the wlandev structure for the
762 * zero on success, non-zero otherwise.
764 * Should be process thread. We'll assume it might be
765 * interrupt though. When we add support for statically
766 * compiled drivers, this function will be called in the
767 * context of the kernel startup code.
768 ----------------------------------------------------------------*/
769 int wlan_setup(wlandevice_t *wlandev)
774 /* Set up the wlandev */
775 wlandev->state = WLAN_DEVICE_CLOSED;
776 wlandev->ethconv = WLAN_ETHCONV_8021h;
777 wlandev->macmode = WLAN_MACMODE_NONE;
779 /* Set up the rx queue */
780 skb_queue_head_init(&wlandev->nsd_rxq);
781 tasklet_init(&wlandev->rx_bh,
783 (unsigned long)wlandev);
785 /* Allocate and initialize the struct device */
786 dev = alloc_netdev(0,"wlan%d",ether_setup);
788 printk(KERN_ERR "Failed to alloc netdev.\n");
791 wlandev->netdev = dev;
792 dev->ml_priv = wlandev;
793 dev->hard_start_xmit = p80211knetdev_hard_start_xmit;
794 dev->get_stats = p80211knetdev_get_stats;
795 #ifdef HAVE_PRIVATE_IOCTL
796 dev->do_ioctl = p80211knetdev_do_ioctl;
798 #ifdef HAVE_MULTICAST
799 dev->set_multicast_list = p80211knetdev_set_multicast_list;
801 dev->init = p80211knetdev_init;
802 dev->open = p80211knetdev_open;
803 dev->stop = p80211knetdev_stop;
805 #if (WIRELESS_EXT < 21)
806 dev->get_wireless_stats = p80211wext_get_wireless_stats;
808 dev->wireless_handlers = &p80211wext_handler_def;
810 netif_stop_queue(dev);
811 #ifdef HAVE_CHANGE_MTU
812 dev->change_mtu = wlan_change_mtu;
814 #ifdef HAVE_SET_MAC_ADDR
815 dev->set_mac_address = p80211knetdev_set_mac_address;
817 #ifdef HAVE_TX_TIMEOUT
818 dev->tx_timeout = &p80211knetdev_tx_timeout;
819 dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000;
821 netif_carrier_off(dev);
827 /*----------------------------------------------------------------
830 * This function is paired with the wlan_setup routine. It should
831 * be called after unregister_wlandev. Basically, all it does is
832 * free the 'struct device' that's associated with the wlandev.
833 * We do it here because the 'struct device' isn't allocated
834 * explicitly in the driver code, it's done in wlan_setup. To
835 * do the free in the driver might seem like 'magic'.
838 * wlandev ptr to the wlandev structure for the
841 * zero on success, non-zero otherwise.
843 * Should be process thread. We'll assume it might be
844 * interrupt though. When we add support for statically
845 * compiled drivers, this function will be called in the
846 * context of the kernel startup code.
847 ----------------------------------------------------------------*/
848 int wlan_unsetup(wlandevice_t *wlandev)
852 tasklet_kill(&wlandev->rx_bh);
854 if (wlandev->netdev == NULL ) {
855 printk(KERN_ERR "called without wlandev->netdev set.\n");
858 free_netdev(wlandev->netdev);
859 wlandev->netdev = NULL;
867 /*----------------------------------------------------------------
870 * Roughly matches the functionality of register_netdev. This function
871 * is called after the driver has successfully probed and set up the
872 * resources for the device. It's now ready to become a named device
873 * in the Linux system.
875 * First we allocate a name for the device (if not already set), then
876 * we call the Linux function register_netdevice.
879 * wlandev ptr to the wlandev structure for the
882 * zero on success, non-zero otherwise.
884 * Can be either interrupt or not.
885 ----------------------------------------------------------------*/
886 int register_wlandev(wlandevice_t *wlandev)
890 i = register_netdev(wlandev->netdev);
898 /*----------------------------------------------------------------
901 * Roughly matches the functionality of unregister_netdev. This
902 * function is called to remove a named device from the system.
904 * First we tell linux that the device should no longer exist.
905 * Then we remove it from the list of known wlan devices.
908 * wlandev ptr to the wlandev structure for the
911 * zero on success, non-zero otherwise.
913 * Can be either interrupt or not.
914 ----------------------------------------------------------------*/
915 int unregister_wlandev(wlandevice_t *wlandev)
919 unregister_netdev(wlandev->netdev);
921 /* Now to clean out the rx queue */
922 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
930 /*----------------------------------------------------------------
931 * p80211netdev_hwremoved
933 * Hardware removed notification. This function should be called
934 * immediately after an MSD has detected that the underlying hardware
935 * has been yanked out from under us. The primary things we need
938 * - Prevent any further traffic from the knetdev i/f
939 * - Prevent any further requests from mgmt i/f
940 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
942 * - Call the MSD hwremoved function.
944 * The remainder of the cleanup will be handled by unregister().
945 * Our primary goal here is to prevent as much tickling of the MSD
946 * as possible since the MSD is already in a 'wounded' state.
948 * TODO: As new features are added, this function should be
952 * wlandev WLAN network device structure
959 ----------------------------------------------------------------*/
960 void p80211netdev_hwremoved(wlandevice_t *wlandev)
962 wlandev->hwremoved = 1;
963 if ( wlandev->state == WLAN_DEVICE_OPEN) {
964 netif_stop_queue(wlandev->netdev);
967 netif_device_detach(wlandev->netdev);
971 /*----------------------------------------------------------------
974 * Classifies the frame, increments the appropriate counter, and
975 * returns 0|1|2 indicating whether the driver should handle, ignore, or
979 * wlandev wlan device structure
980 * fc frame control field
983 * zero if the frame should be handled by the driver,
984 * one if the frame should be ignored
985 * anything else means we drop it.
991 ----------------------------------------------------------------*/
992 static int p80211_rx_typedrop( wlandevice_t *wlandev, u16 fc)
997 /* Classify frame, increment counter */
998 ftype = WLAN_GET_FC_FTYPE(fc);
999 fstype = WLAN_GET_FC_FSTYPE(fc);
1002 "rx_typedrop : ftype=%d fstype=%d.\n", ftype, fstype);
1005 case WLAN_FTYPE_MGMT:
1006 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1007 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1011 WLAN_LOG_DEBUG(3, "rx'd mgmt:\n");
1014 case WLAN_FSTYPE_ASSOCREQ:
1015 /* printk("assocreq"); */
1016 wlandev->rx.assocreq++;
1018 case WLAN_FSTYPE_ASSOCRESP:
1019 /* printk("assocresp"); */
1020 wlandev->rx.assocresp++;
1022 case WLAN_FSTYPE_REASSOCREQ:
1023 /* printk("reassocreq"); */
1024 wlandev->rx.reassocreq++;
1026 case WLAN_FSTYPE_REASSOCRESP:
1027 /* printk("reassocresp"); */
1028 wlandev->rx.reassocresp++;
1030 case WLAN_FSTYPE_PROBEREQ:
1031 /* printk("probereq"); */
1032 wlandev->rx.probereq++;
1034 case WLAN_FSTYPE_PROBERESP:
1035 /* printk("proberesp"); */
1036 wlandev->rx.proberesp++;
1038 case WLAN_FSTYPE_BEACON:
1039 /* printk("beacon"); */
1040 wlandev->rx.beacon++;
1042 case WLAN_FSTYPE_ATIM:
1043 /* printk("atim"); */
1046 case WLAN_FSTYPE_DISASSOC:
1047 /* printk("disassoc"); */
1048 wlandev->rx.disassoc++;
1050 case WLAN_FSTYPE_AUTHEN:
1051 /* printk("authen"); */
1052 wlandev->rx.authen++;
1054 case WLAN_FSTYPE_DEAUTHEN:
1055 /* printk("deauthen"); */
1056 wlandev->rx.deauthen++;
1059 /* printk("unknown"); */
1060 wlandev->rx.mgmt_unknown++;
1067 case WLAN_FTYPE_CTL:
1068 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1069 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1073 WLAN_LOG_DEBUG(3, "rx'd ctl:\n");
1076 case WLAN_FSTYPE_PSPOLL:
1077 /* printk("pspoll"); */
1078 wlandev->rx.pspoll++;
1080 case WLAN_FSTYPE_RTS:
1081 /* printk("rts"); */
1084 case WLAN_FSTYPE_CTS:
1085 /* printk("cts"); */
1088 case WLAN_FSTYPE_ACK:
1089 /* printk("ack"); */
1092 case WLAN_FSTYPE_CFEND:
1093 /* printk("cfend"); */
1094 wlandev->rx.cfend++;
1096 case WLAN_FSTYPE_CFENDCFACK:
1097 /* printk("cfendcfack"); */
1098 wlandev->rx.cfendcfack++;
1101 /* printk("unknown"); */
1102 wlandev->rx.ctl_unknown++;
1109 case WLAN_FTYPE_DATA:
1112 case WLAN_FSTYPE_DATAONLY:
1113 wlandev->rx.dataonly++;
1115 case WLAN_FSTYPE_DATA_CFACK:
1116 wlandev->rx.data_cfack++;
1118 case WLAN_FSTYPE_DATA_CFPOLL:
1119 wlandev->rx.data_cfpoll++;
1121 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1122 wlandev->rx.data__cfack_cfpoll++;
1124 case WLAN_FSTYPE_NULL:
1125 WLAN_LOG_DEBUG(3, "rx'd data:null\n");
1128 case WLAN_FSTYPE_CFACK:
1129 WLAN_LOG_DEBUG(3, "rx'd data:cfack\n");
1130 wlandev->rx.cfack++;
1132 case WLAN_FSTYPE_CFPOLL:
1133 WLAN_LOG_DEBUG(3, "rx'd data:cfpoll\n");
1134 wlandev->rx.cfpoll++;
1136 case WLAN_FSTYPE_CFACK_CFPOLL:
1137 WLAN_LOG_DEBUG(3, "rx'd data:cfack_cfpoll\n");
1138 wlandev->rx.cfack_cfpoll++;
1141 /* printk("unknown"); */
1142 wlandev->rx.data_unknown++;
1151 static void p80211knetdev_tx_timeout( netdevice_t *netdev)
1153 wlandevice_t *wlandev = netdev->ml_priv;
1155 if (wlandev->tx_timeout) {
1156 wlandev->tx_timeout(wlandev);
1158 printk(KERN_WARNING "Implement tx_timeout for %s\n",
1160 netif_wake_queue(wlandev->netdev);