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 /*================================================================*/
139 /* Function Definitions */
141 /*----------------------------------------------------------------
144 * Init method for a Linux netdevice. Called in response to
152 ----------------------------------------------------------------*/
153 static int p80211knetdev_init( netdevice_t *netdev)
155 /* Called in response to register_netdev */
156 /* This is usually the probe function, but the probe has */
157 /* already been done by the MSD and the create_kdev */
158 /* function. All we do here is return success */
163 /*----------------------------------------------------------------
164 * p80211knetdev_get_stats
166 * Statistics retrieval for linux netdevices. Here we're reporting
167 * the Linux i/f level statistics. Hence, for the primary numbers,
168 * we don't want to report the numbers from the MIB. Eventually,
169 * it might be useful to collect some of the error counters though.
172 * netdev Linux netdevice
175 * the address of the statistics structure
176 ----------------------------------------------------------------*/
177 static struct net_device_stats*
178 p80211knetdev_get_stats(netdevice_t *netdev)
180 wlandevice_t *wlandev = netdev->ml_priv;
182 /* TODO: review the MIB stats for items that correspond to
185 return &(wlandev->linux_stats);
189 /*----------------------------------------------------------------
192 * Linux netdevice open method. Following a successful call here,
193 * the device is supposed to be ready for tx and rx. In our
194 * situation that may not be entirely true due to the state of the
198 * netdev Linux network device structure
201 * zero on success, non-zero otherwise
202 ----------------------------------------------------------------*/
203 static int p80211knetdev_open( netdevice_t *netdev )
205 int result = 0; /* success */
206 wlandevice_t *wlandev = netdev->ml_priv;
208 /* Check to make sure the MSD is running */
209 if ( wlandev->msdstate != WLAN_MSD_RUNNING ) {
213 /* Tell the MSD to open */
214 if ( wlandev->open != NULL) {
215 result = wlandev->open(wlandev);
217 netif_start_queue(wlandev->netdev);
218 wlandev->state = WLAN_DEVICE_OPEN;
228 /*----------------------------------------------------------------
231 * Linux netdevice stop (close) method. Following this call,
232 * no frames should go up or down through this interface.
235 * netdev Linux network device structure
238 * zero on success, non-zero otherwise
239 ----------------------------------------------------------------*/
240 static int p80211knetdev_stop( netdevice_t *netdev )
243 wlandevice_t *wlandev = netdev->ml_priv;
245 if ( wlandev->close != NULL ) {
246 result = wlandev->close(wlandev);
249 netif_stop_queue(wlandev->netdev);
250 wlandev->state = WLAN_DEVICE_CLOSED;
255 /*----------------------------------------------------------------
258 * Frame receive function called by the mac specific driver.
261 * wlandev WLAN network device structure
262 * skb skbuff containing a full 802.11 frame.
267 ----------------------------------------------------------------*/
269 p80211netdev_rx(wlandevice_t *wlandev, struct sk_buff *skb )
271 /* Enqueue for post-irq processing */
272 skb_queue_tail(&wlandev->nsd_rxq, skb);
274 tasklet_schedule(&wlandev->rx_bh);
279 /*----------------------------------------------------------------
282 * Deferred processing of all received frames.
285 * wlandev WLAN network device structure
286 * skb skbuff containing a full 802.11 frame.
291 ----------------------------------------------------------------*/
292 static void p80211netdev_rx_bh(unsigned long arg)
294 wlandevice_t *wlandev = (wlandevice_t *) arg;
295 struct sk_buff *skb = NULL;
296 netdevice_t *dev = wlandev->netdev;
297 p80211_hdr_a3_t *hdr;
300 /* Let's empty our our queue */
301 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
302 if (wlandev->state == WLAN_DEVICE_OPEN) {
304 if (dev->type != ARPHRD_ETHER) {
305 /* RAW frame; we shouldn't convert it */
306 // XXX Append the Prism Header here instead.
308 /* set up various data fields */
310 skb_reset_mac_header(skb);
311 skb->ip_summed = CHECKSUM_NONE;
312 skb->pkt_type = PACKET_OTHERHOST;
313 skb->protocol = htons(ETH_P_80211_RAW);
314 dev->last_rx = jiffies;
316 wlandev->linux_stats.rx_packets++;
317 wlandev->linux_stats.rx_bytes += skb->len;
321 hdr = (p80211_hdr_a3_t *)skb->data;
322 fc = le16_to_cpu(hdr->fc);
323 if (p80211_rx_typedrop(wlandev, fc)) {
328 /* perform mcast filtering */
329 if (wlandev->netdev->flags & IFF_ALLMULTI) {
330 /* allow my local address through */
331 if (memcmp(hdr->a1, wlandev->netdev->dev_addr, ETH_ALEN) != 0) {
332 /* but reject anything else that isn't multicast */
333 if (!(hdr->a1[0] & 0x01)) {
340 if ( skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0 ) {
341 skb->dev->last_rx = jiffies;
342 wlandev->linux_stats.rx_packets++;
343 wlandev->linux_stats.rx_bytes += skb->len;
347 pr_debug( "p80211_to_ether failed.\n");
355 /*----------------------------------------------------------------
356 * p80211knetdev_hard_start_xmit
358 * Linux netdevice method for transmitting a frame.
361 * skb Linux sk_buff containing the frame.
362 * netdev Linux netdevice.
365 * If the lower layers report that buffers are full. netdev->tbusy
366 * will be set to prevent higher layers from sending more traffic.
368 * Note: If this function returns non-zero, higher layers retain
369 * ownership of the skb.
372 * zero on success, non-zero on failure.
373 ----------------------------------------------------------------*/
374 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev)
378 wlandevice_t *wlandev = netdev->ml_priv;
379 p80211_hdr_t p80211_hdr;
380 p80211_metawep_t p80211_wep;
386 if (wlandev->state != WLAN_DEVICE_OPEN) {
391 memset(&p80211_hdr, 0, sizeof(p80211_hdr_t));
392 memset(&p80211_wep, 0, sizeof(p80211_metawep_t));
394 if ( netif_queue_stopped(netdev) ) {
395 pr_debug("called when queue stopped.\n");
400 netif_stop_queue(netdev);
402 /* Check to see that a valid mode is set */
403 switch( wlandev->macmode ) {
404 case WLAN_MACMODE_IBSS_STA:
405 case WLAN_MACMODE_ESS_STA:
406 case WLAN_MACMODE_ESS_AP:
409 /* Mode isn't set yet, just drop the frame
410 * and return success .
411 * TODO: we need a saner way to handle this
413 if(skb->protocol != ETH_P_80211_RAW) {
414 netif_start_queue(wlandev->netdev);
416 "Tx attempt prior to association, frame dropped.\n");
417 wlandev->linux_stats.tx_dropped++;
424 /* Check for raw transmits */
425 if(skb->protocol == ETH_P_80211_RAW) {
426 if (!capable(CAP_NET_ADMIN)) {
430 /* move the header over */
431 memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));
432 skb_pull(skb, sizeof(p80211_hdr_t));
434 if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {
436 pr_debug("ether_to_80211(%d) failed.\n",
442 if ( wlandev->txframe == NULL ) {
447 netdev->trans_start = jiffies;
449 wlandev->linux_stats.tx_packets++;
450 /* count only the packet payload */
451 wlandev->linux_stats.tx_bytes += skb->len;
453 txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);
455 if ( txresult == 0) {
456 /* success and more buf */
457 /* avail, re: hw_txdata */
458 netif_wake_queue(wlandev->netdev);
460 } else if ( txresult == 1 ) {
461 /* success, no more avail */
462 pr_debug("txframe success, no more bufs\n");
463 /* netdev->tbusy = 1; don't set here, irqhdlr */
464 /* may have already cleared it */
466 } else if ( txresult == 2 ) {
467 /* alloc failure, drop frame */
468 pr_debug("txframe returned alloc_fail\n");
471 /* buffer full or queue busy, drop frame. */
472 pr_debug("txframe returned full or busy\n");
477 /* Free up the WEP buffer if it's not the same as the skb */
478 if ((p80211_wep.data) && (p80211_wep.data != skb->data))
479 kfree(p80211_wep.data);
481 /* we always free the skb here, never in a lower level. */
489 /*----------------------------------------------------------------
490 * p80211knetdev_set_multicast_list
492 * Called from higher lavers whenever there's a need to set/clear
493 * promiscuous mode or rewrite the multicast list.
500 ----------------------------------------------------------------*/
501 static void p80211knetdev_set_multicast_list(netdevice_t *dev)
503 wlandevice_t *wlandev = dev->ml_priv;
505 /* TODO: real multicast support as well */
507 if (wlandev->set_multicast_list)
508 wlandev->set_multicast_list(wlandev, dev);
514 static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
517 struct ethtool_drvinfo info;
518 struct ethtool_value edata;
520 memset(&info, 0, sizeof(info));
521 memset(&edata, 0, sizeof(edata));
523 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
527 case ETHTOOL_GDRVINFO:
529 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
531 snprintf(info.version, sizeof(info.version), "%s",
537 if (copy_to_user(useraddr, &info, sizeof(info)))
544 if (wlandev->linkstatus &&
545 (wlandev->macmode != WLAN_MACMODE_NONE)) {
551 if (copy_to_user(useraddr, &edata, sizeof(edata)))
562 /*----------------------------------------------------------------
563 * p80211knetdev_do_ioctl
565 * Handle an ioctl call on one of our devices. Everything Linux
566 * ioctl specific is done here. Then we pass the contents of the
567 * ifr->data to the request message handler.
570 * dev Linux kernel netdevice
571 * ifr Our private ioctl request structure, typed for the
572 * generic struct ifreq so we can use ptr to func
576 * zero on success, a negative errno on failure. Possible values:
577 * -ENETDOWN Device isn't up.
578 * -EBUSY cmd already in progress
579 * -ETIME p80211 cmd timed out (MSD may have its own timers)
580 * -EFAULT memory fault copying msg from user buffer
581 * -ENOMEM unable to allocate kernel msg buffer
582 * -ENOSYS bad magic, it the cmd really for us?
583 * -EintR sleeping on cmd, awakened by signal, cmd cancelled.
586 * Process thread (ioctl caller). TODO: SMP support may require
588 ----------------------------------------------------------------*/
589 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd)
592 p80211ioctl_req_t *req = (p80211ioctl_req_t*)ifr;
593 wlandevice_t *wlandev = dev->ml_priv;
596 pr_debug("rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
599 if (cmd == SIOCETHTOOL) {
600 result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);
605 /* Test the magic, assume ifr is good if it's there */
606 if ( req->magic != P80211_IOCTL_MAGIC ) {
611 if ( cmd == P80211_IFTEST ) {
614 } else if ( cmd != P80211_IFREQ ) {
619 /* Allocate a buf of size req->len */
620 if ((msgbuf = kmalloc( req->len, GFP_KERNEL))) {
621 if ( copy_from_user( msgbuf, (void __user *) req->data, req->len) ) {
624 result = p80211req_dorequest( wlandev, msgbuf);
628 if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {
637 return result; /* If allocate,copyfrom or copyto fails, return errno */
640 /*----------------------------------------------------------------
641 * p80211knetdev_set_mac_address
643 * Handles the ioctl for changing the MACAddress of a netdevice
645 * references: linux/netdevice.h and drivers/net/net_init.c
647 * NOTE: [MSM] We only prevent address changes when the netdev is
648 * up. We don't control anything based on dot11 state. If the
649 * address is changed on a STA that's currently associated, you
650 * will probably lose the ability to send and receive data frames.
651 * Just be aware. Therefore, this should usually only be done
652 * prior to scan/join/auth/assoc.
655 * dev netdevice struct
656 * addr the new MACAddress (a struct)
659 * zero on success, a negative errno on failure. Possible values:
660 * -EBUSY device is bussy (cmd not possible)
661 * -and errors returned by: p80211req_dorequest(..)
663 * by: Collin R. Mulliner <collin@mulliner.org>
664 ----------------------------------------------------------------*/
665 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr)
667 struct sockaddr *new_addr = addr;
668 p80211msg_dot11req_mibset_t dot11req;
669 p80211item_unk392_t *mibattr;
670 p80211item_pstr6_t *macaddr;
671 p80211item_uint32_t *resultcode;
674 /* If we're running, we don't allow MAC address changes */
675 if (netif_running(dev)) {
679 /* Set up some convenience pointers. */
680 mibattr = &dot11req.mibattribute;
681 macaddr = (p80211item_pstr6_t*)&mibattr->data;
682 resultcode = &dot11req.resultcode;
684 /* Set up a dot11req_mibset */
685 memset(&dot11req, 0, sizeof(p80211msg_dot11req_mibset_t));
686 dot11req.msgcode = DIDmsg_dot11req_mibset;
687 dot11req.msglen = sizeof(p80211msg_dot11req_mibset_t);
688 memcpy(dot11req.devname,
689 ((wlandevice_t *)dev->ml_priv)->name,
690 WLAN_DEVNAMELEN_MAX - 1);
692 /* Set up the mibattribute argument */
693 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
694 mibattr->status = P80211ENUM_msgitem_status_data_ok;
695 mibattr->len = sizeof(mibattr->data);
697 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;
698 macaddr->status = P80211ENUM_msgitem_status_data_ok;
699 macaddr->len = sizeof(macaddr->data);
700 macaddr->data.len = ETH_ALEN;
701 memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN);
703 /* Set up the resultcode argument */
704 resultcode->did = DIDmsg_dot11req_mibset_resultcode;
705 resultcode->status = P80211ENUM_msgitem_status_no_value;
706 resultcode->len = sizeof(resultcode->data);
707 resultcode->data = 0;
709 /* now fire the request */
710 result = p80211req_dorequest(dev->ml_priv, (u8 *)&dot11req);
712 /* If the request wasn't successful, report an error and don't
713 * change the netdev address
715 if ( result != 0 || resultcode->data != P80211ENUM_resultcode_success) {
717 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
718 result = -EADDRNOTAVAIL;
720 /* everything's ok, change the addr in netdev */
721 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
727 static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
729 // 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
730 // and another 8 for wep.
731 if ( (new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))
741 /*----------------------------------------------------------------
744 * Roughly matches the functionality of ether_setup. Here
745 * we set up any members of the wlandevice structure that are common
746 * to all devices. Additionally, we allocate a linux 'struct device'
747 * and perform the same setup as ether_setup.
749 * Note: It's important that the caller have setup the wlandev->name
750 * ptr prior to calling this function.
753 * wlandev ptr to the wlandev structure for the
756 * zero on success, non-zero otherwise.
758 * Should be process thread. We'll assume it might be
759 * interrupt though. When we add support for statically
760 * compiled drivers, this function will be called in the
761 * context of the kernel startup code.
762 ----------------------------------------------------------------*/
763 int wlan_setup(wlandevice_t *wlandev)
768 /* Set up the wlandev */
769 wlandev->state = WLAN_DEVICE_CLOSED;
770 wlandev->ethconv = WLAN_ETHCONV_8021h;
771 wlandev->macmode = WLAN_MACMODE_NONE;
773 /* Set up the rx queue */
774 skb_queue_head_init(&wlandev->nsd_rxq);
775 tasklet_init(&wlandev->rx_bh,
777 (unsigned long)wlandev);
779 /* Allocate and initialize the struct device */
780 dev = alloc_netdev(0,"wlan%d",ether_setup);
782 printk(KERN_ERR "Failed to alloc netdev.\n");
785 wlandev->netdev = dev;
786 dev->ml_priv = wlandev;
787 dev->hard_start_xmit = p80211knetdev_hard_start_xmit;
788 dev->get_stats = p80211knetdev_get_stats;
789 #ifdef HAVE_PRIVATE_IOCTL
790 dev->do_ioctl = p80211knetdev_do_ioctl;
792 #ifdef HAVE_MULTICAST
793 dev->set_multicast_list = p80211knetdev_set_multicast_list;
795 dev->init = p80211knetdev_init;
796 dev->open = p80211knetdev_open;
797 dev->stop = p80211knetdev_stop;
799 #if (WIRELESS_EXT < 21)
800 dev->get_wireless_stats = p80211wext_get_wireless_stats;
802 dev->wireless_handlers = &p80211wext_handler_def;
804 netif_stop_queue(dev);
805 #ifdef HAVE_CHANGE_MTU
806 dev->change_mtu = wlan_change_mtu;
808 #ifdef HAVE_SET_MAC_ADDR
809 dev->set_mac_address = p80211knetdev_set_mac_address;
811 #ifdef HAVE_TX_TIMEOUT
812 dev->tx_timeout = &p80211knetdev_tx_timeout;
813 dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000;
815 netif_carrier_off(dev);
821 /*----------------------------------------------------------------
824 * This function is paired with the wlan_setup routine. It should
825 * be called after unregister_wlandev. Basically, all it does is
826 * free the 'struct device' that's associated with the wlandev.
827 * We do it here because the 'struct device' isn't allocated
828 * explicitly in the driver code, it's done in wlan_setup. To
829 * do the free in the driver might seem like 'magic'.
832 * wlandev ptr to the wlandev structure for the
835 * zero on success, non-zero otherwise.
837 * Should be process thread. We'll assume it might be
838 * interrupt though. When we add support for statically
839 * compiled drivers, this function will be called in the
840 * context of the kernel startup code.
841 ----------------------------------------------------------------*/
842 int wlan_unsetup(wlandevice_t *wlandev)
846 tasklet_kill(&wlandev->rx_bh);
848 if (wlandev->netdev == NULL ) {
849 printk(KERN_ERR "called without wlandev->netdev set.\n");
852 free_netdev(wlandev->netdev);
853 wlandev->netdev = NULL;
861 /*----------------------------------------------------------------
864 * Roughly matches the functionality of register_netdev. This function
865 * is called after the driver has successfully probed and set up the
866 * resources for the device. It's now ready to become a named device
867 * in the Linux system.
869 * First we allocate a name for the device (if not already set), then
870 * we call the Linux function register_netdevice.
873 * wlandev ptr to the wlandev structure for the
876 * zero on success, non-zero otherwise.
878 * Can be either interrupt or not.
879 ----------------------------------------------------------------*/
880 int register_wlandev(wlandevice_t *wlandev)
884 i = register_netdev(wlandev->netdev);
892 /*----------------------------------------------------------------
895 * Roughly matches the functionality of unregister_netdev. This
896 * function is called to remove a named device from the system.
898 * First we tell linux that the device should no longer exist.
899 * Then we remove it from the list of known wlan devices.
902 * wlandev ptr to the wlandev structure for the
905 * zero on success, non-zero otherwise.
907 * Can be either interrupt or not.
908 ----------------------------------------------------------------*/
909 int unregister_wlandev(wlandevice_t *wlandev)
913 unregister_netdev(wlandev->netdev);
915 /* Now to clean out the rx queue */
916 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
924 /*----------------------------------------------------------------
925 * p80211netdev_hwremoved
927 * Hardware removed notification. This function should be called
928 * immediately after an MSD has detected that the underlying hardware
929 * has been yanked out from under us. The primary things we need
932 * - Prevent any further traffic from the knetdev i/f
933 * - Prevent any further requests from mgmt i/f
934 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
936 * - Call the MSD hwremoved function.
938 * The remainder of the cleanup will be handled by unregister().
939 * Our primary goal here is to prevent as much tickling of the MSD
940 * as possible since the MSD is already in a 'wounded' state.
942 * TODO: As new features are added, this function should be
946 * wlandev WLAN network device structure
953 ----------------------------------------------------------------*/
954 void p80211netdev_hwremoved(wlandevice_t *wlandev)
956 wlandev->hwremoved = 1;
957 if ( wlandev->state == WLAN_DEVICE_OPEN) {
958 netif_stop_queue(wlandev->netdev);
961 netif_device_detach(wlandev->netdev);
965 /*----------------------------------------------------------------
968 * Classifies the frame, increments the appropriate counter, and
969 * returns 0|1|2 indicating whether the driver should handle, ignore, or
973 * wlandev wlan device structure
974 * fc frame control field
977 * zero if the frame should be handled by the driver,
978 * one if the frame should be ignored
979 * anything else means we drop it.
985 ----------------------------------------------------------------*/
986 static int p80211_rx_typedrop( wlandevice_t *wlandev, u16 fc)
991 /* Classify frame, increment counter */
992 ftype = WLAN_GET_FC_FTYPE(fc);
993 fstype = WLAN_GET_FC_FSTYPE(fc);
996 "rx_typedrop : ftype=%d fstype=%d.\n", ftype, fstype);
999 case WLAN_FTYPE_MGMT:
1000 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1001 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1005 pr_debug("rx'd mgmt:\n");
1008 case WLAN_FSTYPE_ASSOCREQ:
1009 /* printk("assocreq"); */
1010 wlandev->rx.assocreq++;
1012 case WLAN_FSTYPE_ASSOCRESP:
1013 /* printk("assocresp"); */
1014 wlandev->rx.assocresp++;
1016 case WLAN_FSTYPE_REASSOCREQ:
1017 /* printk("reassocreq"); */
1018 wlandev->rx.reassocreq++;
1020 case WLAN_FSTYPE_REASSOCRESP:
1021 /* printk("reassocresp"); */
1022 wlandev->rx.reassocresp++;
1024 case WLAN_FSTYPE_PROBEREQ:
1025 /* printk("probereq"); */
1026 wlandev->rx.probereq++;
1028 case WLAN_FSTYPE_PROBERESP:
1029 /* printk("proberesp"); */
1030 wlandev->rx.proberesp++;
1032 case WLAN_FSTYPE_BEACON:
1033 /* printk("beacon"); */
1034 wlandev->rx.beacon++;
1036 case WLAN_FSTYPE_ATIM:
1037 /* printk("atim"); */
1040 case WLAN_FSTYPE_DISASSOC:
1041 /* printk("disassoc"); */
1042 wlandev->rx.disassoc++;
1044 case WLAN_FSTYPE_AUTHEN:
1045 /* printk("authen"); */
1046 wlandev->rx.authen++;
1048 case WLAN_FSTYPE_DEAUTHEN:
1049 /* printk("deauthen"); */
1050 wlandev->rx.deauthen++;
1053 /* printk("unknown"); */
1054 wlandev->rx.mgmt_unknown++;
1061 case WLAN_FTYPE_CTL:
1062 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1063 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1067 pr_debug("rx'd ctl:\n");
1070 case WLAN_FSTYPE_PSPOLL:
1071 /* printk("pspoll"); */
1072 wlandev->rx.pspoll++;
1074 case WLAN_FSTYPE_RTS:
1075 /* printk("rts"); */
1078 case WLAN_FSTYPE_CTS:
1079 /* printk("cts"); */
1082 case WLAN_FSTYPE_ACK:
1083 /* printk("ack"); */
1086 case WLAN_FSTYPE_CFEND:
1087 /* printk("cfend"); */
1088 wlandev->rx.cfend++;
1090 case WLAN_FSTYPE_CFENDCFACK:
1091 /* printk("cfendcfack"); */
1092 wlandev->rx.cfendcfack++;
1095 /* printk("unknown"); */
1096 wlandev->rx.ctl_unknown++;
1103 case WLAN_FTYPE_DATA:
1106 case WLAN_FSTYPE_DATAONLY:
1107 wlandev->rx.dataonly++;
1109 case WLAN_FSTYPE_DATA_CFACK:
1110 wlandev->rx.data_cfack++;
1112 case WLAN_FSTYPE_DATA_CFPOLL:
1113 wlandev->rx.data_cfpoll++;
1115 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1116 wlandev->rx.data__cfack_cfpoll++;
1118 case WLAN_FSTYPE_NULL:
1119 pr_debug("rx'd data:null\n");
1122 case WLAN_FSTYPE_CFACK:
1123 pr_debug("rx'd data:cfack\n");
1124 wlandev->rx.cfack++;
1126 case WLAN_FSTYPE_CFPOLL:
1127 pr_debug("rx'd data:cfpoll\n");
1128 wlandev->rx.cfpoll++;
1130 case WLAN_FSTYPE_CFACK_CFPOLL:
1131 pr_debug("rx'd data:cfack_cfpoll\n");
1132 wlandev->rx.cfack_cfpoll++;
1135 /* printk("unknown"); */
1136 wlandev->rx.data_unknown++;
1145 static void p80211knetdev_tx_timeout( netdevice_t *netdev)
1147 wlandevice_t *wlandev = netdev->ml_priv;
1149 if (wlandev->tx_timeout) {
1150 wlandev->tx_timeout(wlandev);
1152 printk(KERN_WARNING "Implement tx_timeout for %s\n",
1154 netif_wake_queue(wlandev->netdev);