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>
75 #include <asm/bitops.h>
76 #include <asm/uaccess.h>
77 #include <asm/byteorder.h>
80 #include <linux/ethtool.h>
83 #include <net/iw_handler.h>
84 #include <net/net_namespace.h>
86 /*================================================================*/
87 /* Project Includes */
89 #include "wlan_compat.h"
90 #include "p80211types.h"
91 #include "p80211hdr.h"
92 #include "p80211conv.h"
93 #include "p80211mgmt.h"
94 #include "p80211msg.h"
95 #include "p80211netdev.h"
96 #include "p80211ioctl.h"
97 #include "p80211req.h"
98 #include "p80211metastruct.h"
99 #include "p80211metadef.h"
101 /*================================================================*/
102 /* Local Constants */
104 /*================================================================*/
108 /*================================================================*/
111 /*================================================================*/
112 /* Local Function Declarations */
114 /* Support functions */
115 static void p80211netdev_rx_bh(unsigned long arg);
117 /* netdevice method functions */
118 static int p80211knetdev_init( netdevice_t *netdev);
119 static struct net_device_stats* p80211knetdev_get_stats(netdevice_t *netdev);
120 static int p80211knetdev_open( netdevice_t *netdev);
121 static int p80211knetdev_stop( netdevice_t *netdev );
122 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev);
123 static void p80211knetdev_set_multicast_list(netdevice_t *dev);
124 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd);
125 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr);
126 static void p80211knetdev_tx_timeout(netdevice_t *netdev);
127 static int p80211_rx_typedrop( wlandevice_t *wlandev, u16 fc);
129 int wlan_watchdog = 5000;
130 module_param(wlan_watchdog, int, 0644);
131 MODULE_PARM_DESC(wlan_watchdog, "transmit timeout in milliseconds");
133 int wlan_wext_write = 1;
134 module_param(wlan_wext_write, int, 0644);
135 MODULE_PARM_DESC(wlan_wext_write, "enable write wireless extensions");
137 #ifdef WLAN_INCLUDE_DEBUG
139 module_param(wlan_debug, int, 0644);
140 MODULE_PARM_DESC(wlan_debug, "p80211 debug level");
143 /*================================================================*/
144 /* Function Definitions */
146 /*----------------------------------------------------------------
149 * Init method for a Linux netdevice. Called in response to
157 ----------------------------------------------------------------*/
158 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 */
170 /*----------------------------------------------------------------
171 * p80211knetdev_get_stats
173 * Statistics retrieval for linux netdevices. Here we're reporting
174 * the Linux i/f level statistics. Hence, for the primary numbers,
175 * we don't want to report the numbers from the MIB. Eventually,
176 * it might be useful to collect some of the error counters though.
179 * netdev Linux netdevice
182 * the address of the statistics structure
183 ----------------------------------------------------------------*/
184 static struct net_device_stats*
185 p80211knetdev_get_stats(netdevice_t *netdev)
187 wlandevice_t *wlandev = netdev->ml_priv;
190 /* TODO: review the MIB stats for items that correspond to
194 return &(wlandev->linux_stats);
198 /*----------------------------------------------------------------
201 * Linux netdevice open method. Following a successful call here,
202 * the device is supposed to be ready for tx and rx. In our
203 * situation that may not be entirely true due to the state of the
207 * netdev Linux network device structure
210 * zero on success, non-zero otherwise
211 ----------------------------------------------------------------*/
212 static int p80211knetdev_open( netdevice_t *netdev )
214 int result = 0; /* success */
215 wlandevice_t *wlandev = netdev->ml_priv;
219 /* Check to make sure the MSD is running */
220 if ( wlandev->msdstate != WLAN_MSD_RUNNING ) {
224 /* Tell the MSD to open */
225 if ( wlandev->open != NULL) {
226 result = wlandev->open(wlandev);
228 netif_start_queue(wlandev->netdev);
229 wlandev->state = WLAN_DEVICE_OPEN;
240 /*----------------------------------------------------------------
243 * Linux netdevice stop (close) method. Following this call,
244 * no frames should go up or down through this interface.
247 * netdev Linux network device structure
250 * zero on success, non-zero otherwise
251 ----------------------------------------------------------------*/
252 static int p80211knetdev_stop( netdevice_t *netdev )
255 wlandevice_t *wlandev = netdev->ml_priv;
259 if ( wlandev->close != NULL ) {
260 result = wlandev->close(wlandev);
263 netif_stop_queue(wlandev->netdev);
264 wlandev->state = WLAN_DEVICE_CLOSED;
270 /*----------------------------------------------------------------
273 * Frame receive function called by the mac specific driver.
276 * wlandev WLAN network device structure
277 * skb skbuff containing a full 802.11 frame.
282 ----------------------------------------------------------------*/
284 p80211netdev_rx(wlandevice_t *wlandev, struct sk_buff *skb )
288 /* Enqueue for post-irq processing */
289 skb_queue_tail(&wlandev->nsd_rxq, skb);
291 tasklet_schedule(&wlandev->rx_bh);
297 /*----------------------------------------------------------------
300 * Deferred processing of all received frames.
303 * wlandev WLAN network device structure
304 * skb skbuff containing a full 802.11 frame.
309 ----------------------------------------------------------------*/
310 static void p80211netdev_rx_bh(unsigned long arg)
312 wlandevice_t *wlandev = (wlandevice_t *) arg;
313 struct sk_buff *skb = NULL;
314 netdevice_t *dev = wlandev->netdev;
315 p80211_hdr_a3_t *hdr;
320 /* Let's empty our our queue */
321 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
322 if (wlandev->state == WLAN_DEVICE_OPEN) {
324 if (dev->type != ARPHRD_ETHER) {
325 /* RAW frame; we shouldn't convert it */
326 // XXX Append the Prism Header here instead.
328 /* set up various data fields */
330 skb_reset_mac_header(skb);
331 skb->ip_summed = CHECKSUM_NONE;
332 skb->pkt_type = PACKET_OTHERHOST;
333 skb->protocol = htons(ETH_P_80211_RAW);
334 dev->last_rx = jiffies;
336 wlandev->linux_stats.rx_packets++;
337 wlandev->linux_stats.rx_bytes += skb->len;
341 hdr = (p80211_hdr_a3_t *)skb->data;
342 fc = ieee2host16(hdr->fc);
343 if (p80211_rx_typedrop(wlandev, fc)) {
348 /* perform mcast filtering */
349 if (wlandev->netdev->flags & IFF_ALLMULTI) {
350 /* allow my local address through */
351 if (memcmp(hdr->a1, wlandev->netdev->dev_addr, ETH_ALEN) != 0) {
352 /* but reject anything else that isn't multicast */
353 if (!(hdr->a1[0] & 0x01)) {
360 if ( skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0 ) {
361 skb->dev->last_rx = jiffies;
362 wlandev->linux_stats.rx_packets++;
363 wlandev->linux_stats.rx_bytes += skb->len;
367 WLAN_LOG_DEBUG(1, "p80211_to_ether failed.\n");
377 /*----------------------------------------------------------------
378 * p80211knetdev_hard_start_xmit
380 * Linux netdevice method for transmitting a frame.
383 * skb Linux sk_buff containing the frame.
384 * netdev Linux netdevice.
387 * If the lower layers report that buffers are full. netdev->tbusy
388 * will be set to prevent higher layers from sending more traffic.
390 * Note: If this function returns non-zero, higher layers retain
391 * ownership of the skb.
394 * zero on success, non-zero on failure.
395 ----------------------------------------------------------------*/
396 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev)
400 wlandevice_t *wlandev = netdev->ml_priv;
401 p80211_hdr_t p80211_hdr;
402 p80211_metawep_t p80211_wep;
410 if (wlandev->state != WLAN_DEVICE_OPEN) {
415 memset(&p80211_hdr, 0, sizeof(p80211_hdr_t));
416 memset(&p80211_wep, 0, sizeof(p80211_metawep_t));
418 if ( netif_queue_stopped(netdev) ) {
419 WLAN_LOG_DEBUG(1, "called when queue stopped.\n");
424 netif_stop_queue(netdev);
426 /* Check to see that a valid mode is set */
427 switch( wlandev->macmode ) {
428 case WLAN_MACMODE_IBSS_STA:
429 case WLAN_MACMODE_ESS_STA:
430 case WLAN_MACMODE_ESS_AP:
433 /* Mode isn't set yet, just drop the frame
434 * and return success .
435 * TODO: we need a saner way to handle this
437 if(skb->protocol != ETH_P_80211_RAW) {
438 netif_start_queue(wlandev->netdev);
440 "Tx attempt prior to association, frame dropped.\n");
441 wlandev->linux_stats.tx_dropped++;
448 /* Check for raw transmits */
449 if(skb->protocol == ETH_P_80211_RAW) {
450 if (!capable(CAP_NET_ADMIN)) {
454 /* move the header over */
455 memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));
456 skb_pull(skb, sizeof(p80211_hdr_t));
458 if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {
460 WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n",
466 if ( wlandev->txframe == NULL ) {
471 netdev->trans_start = jiffies;
473 wlandev->linux_stats.tx_packets++;
474 /* count only the packet payload */
475 wlandev->linux_stats.tx_bytes += skb->len;
477 txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);
479 if ( txresult == 0) {
480 /* success and more buf */
481 /* avail, re: hw_txdata */
482 netif_wake_queue(wlandev->netdev);
484 } else if ( txresult == 1 ) {
485 /* success, no more avail */
486 WLAN_LOG_DEBUG(3, "txframe success, no more bufs\n");
487 /* netdev->tbusy = 1; don't set here, irqhdlr */
488 /* may have already cleared it */
490 } else if ( txresult == 2 ) {
491 /* alloc failure, drop frame */
492 WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");
495 /* buffer full or queue busy, drop frame. */
496 WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");
501 /* Free up the WEP buffer if it's not the same as the skb */
502 if ((p80211_wep.data) && (p80211_wep.data != skb->data))
503 kfree(p80211_wep.data);
505 /* we always free the skb here, never in a lower level. */
514 /*----------------------------------------------------------------
515 * p80211knetdev_set_multicast_list
517 * Called from higher lavers whenever there's a need to set/clear
518 * promiscuous mode or rewrite the multicast list.
525 ----------------------------------------------------------------*/
526 static void p80211knetdev_set_multicast_list(netdevice_t *dev)
528 wlandevice_t *wlandev = dev->ml_priv;
532 /* TODO: real multicast support as well */
534 if (wlandev->set_multicast_list)
535 wlandev->set_multicast_list(wlandev, dev);
542 static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
545 struct ethtool_drvinfo info;
546 struct ethtool_value edata;
548 memset(&info, 0, sizeof(info));
549 memset(&edata, 0, sizeof(edata));
551 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
555 case ETHTOOL_GDRVINFO:
557 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
559 snprintf(info.version, sizeof(info.version), "%s",
565 if (copy_to_user(useraddr, &info, sizeof(info)))
572 if (wlandev->linkstatus &&
573 (wlandev->macmode != WLAN_MACMODE_NONE)) {
579 if (copy_to_user(useraddr, &edata, sizeof(edata)))
590 /*----------------------------------------------------------------
591 * p80211knetdev_do_ioctl
593 * Handle an ioctl call on one of our devices. Everything Linux
594 * ioctl specific is done here. Then we pass the contents of the
595 * ifr->data to the request message handler.
598 * dev Linux kernel netdevice
599 * ifr Our private ioctl request structure, typed for the
600 * generic struct ifreq so we can use ptr to func
604 * zero on success, a negative errno on failure. Possible values:
605 * -ENETDOWN Device isn't up.
606 * -EBUSY cmd already in progress
607 * -ETIME p80211 cmd timed out (MSD may have its own timers)
608 * -EFAULT memory fault copying msg from user buffer
609 * -ENOMEM unable to allocate kernel msg buffer
610 * -ENOSYS bad magic, it the cmd really for us?
611 * -EintR sleeping on cmd, awakened by signal, cmd cancelled.
614 * Process thread (ioctl caller). TODO: SMP support may require
616 ----------------------------------------------------------------*/
617 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd)
620 p80211ioctl_req_t *req = (p80211ioctl_req_t*)ifr;
621 wlandevice_t *wlandev = dev->ml_priv;
625 WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
628 if (cmd == SIOCETHTOOL) {
629 result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);
634 /* Test the magic, assume ifr is good if it's there */
635 if ( req->magic != P80211_IOCTL_MAGIC ) {
640 if ( cmd == P80211_IFTEST ) {
643 } else if ( cmd != P80211_IFREQ ) {
648 /* Allocate a buf of size req->len */
649 if ((msgbuf = kmalloc( req->len, GFP_KERNEL))) {
650 if ( copy_from_user( msgbuf, (void __user *) req->data, req->len) ) {
653 result = p80211req_dorequest( wlandev, msgbuf);
657 if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {
668 return result; /* If allocate,copyfrom or copyto fails, return errno */
671 /*----------------------------------------------------------------
672 * p80211knetdev_set_mac_address
674 * Handles the ioctl for changing the MACAddress of a netdevice
676 * references: linux/netdevice.h and drivers/net/net_init.c
678 * NOTE: [MSM] We only prevent address changes when the netdev is
679 * up. We don't control anything based on dot11 state. If the
680 * address is changed on a STA that's currently associated, you
681 * will probably lose the ability to send and receive data frames.
682 * Just be aware. Therefore, this should usually only be done
683 * prior to scan/join/auth/assoc.
686 * dev netdevice struct
687 * addr the new MACAddress (a struct)
690 * zero on success, a negative errno on failure. Possible values:
691 * -EBUSY device is bussy (cmd not possible)
692 * -and errors returned by: p80211req_dorequest(..)
694 * by: Collin R. Mulliner <collin@mulliner.org>
695 ----------------------------------------------------------------*/
696 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr)
698 struct sockaddr *new_addr = addr;
699 p80211msg_dot11req_mibset_t dot11req;
700 p80211item_unk392_t *mibattr;
701 p80211item_pstr6_t *macaddr;
702 p80211item_uint32_t *resultcode;
706 /* If we're running, we don't allow MAC address changes */
707 if (netif_running(dev)) {
711 /* Set up some convenience pointers. */
712 mibattr = &dot11req.mibattribute;
713 macaddr = (p80211item_pstr6_t*)&mibattr->data;
714 resultcode = &dot11req.resultcode;
716 /* Set up a dot11req_mibset */
717 memset(&dot11req, 0, sizeof(p80211msg_dot11req_mibset_t));
718 dot11req.msgcode = DIDmsg_dot11req_mibset;
719 dot11req.msglen = sizeof(p80211msg_dot11req_mibset_t);
720 memcpy(dot11req.devname,
721 ((wlandevice_t *)dev->ml_priv)->name,
722 WLAN_DEVNAMELEN_MAX - 1);
724 /* Set up the mibattribute argument */
725 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
726 mibattr->status = P80211ENUM_msgitem_status_data_ok;
727 mibattr->len = sizeof(mibattr->data);
729 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;
730 macaddr->status = P80211ENUM_msgitem_status_data_ok;
731 macaddr->len = sizeof(macaddr->data);
732 macaddr->data.len = ETH_ALEN;
733 memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN);
735 /* Set up the resultcode argument */
736 resultcode->did = DIDmsg_dot11req_mibset_resultcode;
737 resultcode->status = P80211ENUM_msgitem_status_no_value;
738 resultcode->len = sizeof(resultcode->data);
739 resultcode->data = 0;
741 /* now fire the request */
742 result = p80211req_dorequest(dev->ml_priv, (u8 *)&dot11req);
744 /* If the request wasn't successful, report an error and don't
745 * change the netdev address
747 if ( result != 0 || resultcode->data != P80211ENUM_resultcode_success) {
749 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
750 result = -EADDRNOTAVAIL;
752 /* everything's ok, change the addr in netdev */
753 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
760 static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
763 // 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
764 // and another 8 for wep.
765 if ( (new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))
777 /*----------------------------------------------------------------
780 * Roughly matches the functionality of ether_setup. Here
781 * we set up any members of the wlandevice structure that are common
782 * to all devices. Additionally, we allocate a linux 'struct device'
783 * and perform the same setup as ether_setup.
785 * Note: It's important that the caller have setup the wlandev->name
786 * ptr prior to calling this function.
789 * wlandev ptr to the wlandev structure for the
792 * zero on success, non-zero otherwise.
794 * Should be process thread. We'll assume it might be
795 * interrupt though. When we add support for statically
796 * compiled drivers, this function will be called in the
797 * context of the kernel startup code.
798 ----------------------------------------------------------------*/
799 int wlan_setup(wlandevice_t *wlandev)
806 /* Set up the wlandev */
807 wlandev->state = WLAN_DEVICE_CLOSED;
808 wlandev->ethconv = WLAN_ETHCONV_8021h;
809 wlandev->macmode = WLAN_MACMODE_NONE;
811 /* Set up the rx queue */
812 skb_queue_head_init(&wlandev->nsd_rxq);
813 tasklet_init(&wlandev->rx_bh,
815 (unsigned long)wlandev);
817 /* Allocate and initialize the struct device */
818 dev = alloc_netdev(0,"wlan%d",ether_setup);
820 WLAN_LOG_ERROR("Failed to alloc netdev.\n");
823 wlandev->netdev = dev;
824 dev->ml_priv = wlandev;
825 dev->hard_start_xmit = p80211knetdev_hard_start_xmit;
826 dev->get_stats = p80211knetdev_get_stats;
827 #ifdef HAVE_PRIVATE_IOCTL
828 dev->do_ioctl = p80211knetdev_do_ioctl;
830 #ifdef HAVE_MULTICAST
831 dev->set_multicast_list = p80211knetdev_set_multicast_list;
833 dev->init = p80211knetdev_init;
834 dev->open = p80211knetdev_open;
835 dev->stop = p80211knetdev_stop;
837 #if (WIRELESS_EXT < 21)
838 dev->get_wireless_stats = p80211wext_get_wireless_stats;
840 dev->wireless_handlers = &p80211wext_handler_def;
842 netif_stop_queue(dev);
843 #ifdef HAVE_CHANGE_MTU
844 dev->change_mtu = wlan_change_mtu;
846 #ifdef HAVE_SET_MAC_ADDR
847 dev->set_mac_address = p80211knetdev_set_mac_address;
849 #ifdef HAVE_TX_TIMEOUT
850 dev->tx_timeout = &p80211knetdev_tx_timeout;
851 dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000;
853 netif_carrier_off(dev);
860 /*----------------------------------------------------------------
863 * This function is paired with the wlan_setup routine. It should
864 * be called after unregister_wlandev. Basically, all it does is
865 * free the 'struct device' that's associated with the wlandev.
866 * We do it here because the 'struct device' isn't allocated
867 * explicitly in the driver code, it's done in wlan_setup. To
868 * do the free in the driver might seem like 'magic'.
871 * wlandev ptr to the wlandev structure for the
874 * zero on success, non-zero otherwise.
876 * Should be process thread. We'll assume it might be
877 * interrupt though. When we add support for statically
878 * compiled drivers, this function will be called in the
879 * context of the kernel startup code.
880 ----------------------------------------------------------------*/
881 int wlan_unsetup(wlandevice_t *wlandev)
887 tasklet_kill(&wlandev->rx_bh);
889 if (wlandev->netdev == NULL ) {
890 WLAN_LOG_ERROR("called without wlandev->netdev set.\n");
893 free_netdev(wlandev->netdev);
894 wlandev->netdev = NULL;
903 /*----------------------------------------------------------------
906 * Roughly matches the functionality of register_netdev. This function
907 * is called after the driver has successfully probed and set up the
908 * resources for the device. It's now ready to become a named device
909 * in the Linux system.
911 * First we allocate a name for the device (if not already set), then
912 * we call the Linux function register_netdevice.
915 * wlandev ptr to the wlandev structure for the
918 * zero on success, non-zero otherwise.
920 * Can be either interrupt or not.
921 ----------------------------------------------------------------*/
922 int register_wlandev(wlandevice_t *wlandev)
928 i = register_netdev(wlandev->netdev);
937 /*----------------------------------------------------------------
940 * Roughly matches the functionality of unregister_netdev. This
941 * function is called to remove a named device from the system.
943 * First we tell linux that the device should no longer exist.
944 * Then we remove it from the list of known wlan devices.
947 * wlandev ptr to the wlandev structure for the
950 * zero on success, non-zero otherwise.
952 * Can be either interrupt or not.
953 ----------------------------------------------------------------*/
954 int unregister_wlandev(wlandevice_t *wlandev)
960 unregister_netdev(wlandev->netdev);
962 /* Now to clean out the rx queue */
963 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
972 /*----------------------------------------------------------------
973 * p80211netdev_hwremoved
975 * Hardware removed notification. This function should be called
976 * immediately after an MSD has detected that the underlying hardware
977 * has been yanked out from under us. The primary things we need
980 * - Prevent any further traffic from the knetdev i/f
981 * - Prevent any further requests from mgmt i/f
982 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
984 * - Call the MSD hwremoved function.
986 * The remainder of the cleanup will be handled by unregister().
987 * Our primary goal here is to prevent as much tickling of the MSD
988 * as possible since the MSD is already in a 'wounded' state.
990 * TODO: As new features are added, this function should be
994 * wlandev WLAN network device structure
1000 * Usually interrupt.
1001 ----------------------------------------------------------------*/
1002 void p80211netdev_hwremoved(wlandevice_t *wlandev)
1005 wlandev->hwremoved = 1;
1006 if ( wlandev->state == WLAN_DEVICE_OPEN) {
1007 netif_stop_queue(wlandev->netdev);
1010 netif_device_detach(wlandev->netdev);
1016 /*----------------------------------------------------------------
1017 * p80211_rx_typedrop
1019 * Classifies the frame, increments the appropriate counter, and
1020 * returns 0|1|2 indicating whether the driver should handle, ignore, or
1024 * wlandev wlan device structure
1025 * fc frame control field
1028 * zero if the frame should be handled by the driver,
1029 * one if the frame should be ignored
1030 * anything else means we drop it.
1036 ----------------------------------------------------------------*/
1037 static int p80211_rx_typedrop( wlandevice_t *wlandev, u16 fc)
1042 /* Classify frame, increment counter */
1043 ftype = WLAN_GET_FC_FTYPE(fc);
1044 fstype = WLAN_GET_FC_FSTYPE(fc);
1047 "rx_typedrop : ftype=%d fstype=%d.\n", ftype, fstype);
1050 case WLAN_FTYPE_MGMT:
1051 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1052 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1056 WLAN_LOG_DEBUG(3, "rx'd mgmt:\n");
1059 case WLAN_FSTYPE_ASSOCREQ:
1060 /* printk("assocreq"); */
1061 wlandev->rx.assocreq++;
1063 case WLAN_FSTYPE_ASSOCRESP:
1064 /* printk("assocresp"); */
1065 wlandev->rx.assocresp++;
1067 case WLAN_FSTYPE_REASSOCREQ:
1068 /* printk("reassocreq"); */
1069 wlandev->rx.reassocreq++;
1071 case WLAN_FSTYPE_REASSOCRESP:
1072 /* printk("reassocresp"); */
1073 wlandev->rx.reassocresp++;
1075 case WLAN_FSTYPE_PROBEREQ:
1076 /* printk("probereq"); */
1077 wlandev->rx.probereq++;
1079 case WLAN_FSTYPE_PROBERESP:
1080 /* printk("proberesp"); */
1081 wlandev->rx.proberesp++;
1083 case WLAN_FSTYPE_BEACON:
1084 /* printk("beacon"); */
1085 wlandev->rx.beacon++;
1087 case WLAN_FSTYPE_ATIM:
1088 /* printk("atim"); */
1091 case WLAN_FSTYPE_DISASSOC:
1092 /* printk("disassoc"); */
1093 wlandev->rx.disassoc++;
1095 case WLAN_FSTYPE_AUTHEN:
1096 /* printk("authen"); */
1097 wlandev->rx.authen++;
1099 case WLAN_FSTYPE_DEAUTHEN:
1100 /* printk("deauthen"); */
1101 wlandev->rx.deauthen++;
1104 /* printk("unknown"); */
1105 wlandev->rx.mgmt_unknown++;
1112 case WLAN_FTYPE_CTL:
1113 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1114 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1118 WLAN_LOG_DEBUG(3, "rx'd ctl:\n");
1121 case WLAN_FSTYPE_PSPOLL:
1122 /* printk("pspoll"); */
1123 wlandev->rx.pspoll++;
1125 case WLAN_FSTYPE_RTS:
1126 /* printk("rts"); */
1129 case WLAN_FSTYPE_CTS:
1130 /* printk("cts"); */
1133 case WLAN_FSTYPE_ACK:
1134 /* printk("ack"); */
1137 case WLAN_FSTYPE_CFEND:
1138 /* printk("cfend"); */
1139 wlandev->rx.cfend++;
1141 case WLAN_FSTYPE_CFENDCFACK:
1142 /* printk("cfendcfack"); */
1143 wlandev->rx.cfendcfack++;
1146 /* printk("unknown"); */
1147 wlandev->rx.ctl_unknown++;
1154 case WLAN_FTYPE_DATA:
1157 case WLAN_FSTYPE_DATAONLY:
1158 wlandev->rx.dataonly++;
1160 case WLAN_FSTYPE_DATA_CFACK:
1161 wlandev->rx.data_cfack++;
1163 case WLAN_FSTYPE_DATA_CFPOLL:
1164 wlandev->rx.data_cfpoll++;
1166 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1167 wlandev->rx.data__cfack_cfpoll++;
1169 case WLAN_FSTYPE_NULL:
1170 WLAN_LOG_DEBUG(3, "rx'd data:null\n");
1173 case WLAN_FSTYPE_CFACK:
1174 WLAN_LOG_DEBUG(3, "rx'd data:cfack\n");
1175 wlandev->rx.cfack++;
1177 case WLAN_FSTYPE_CFPOLL:
1178 WLAN_LOG_DEBUG(3, "rx'd data:cfpoll\n");
1179 wlandev->rx.cfpoll++;
1181 case WLAN_FSTYPE_CFACK_CFPOLL:
1182 WLAN_LOG_DEBUG(3, "rx'd data:cfack_cfpoll\n");
1183 wlandev->rx.cfack_cfpoll++;
1186 /* printk("unknown"); */
1187 wlandev->rx.data_unknown++;
1196 static void p80211knetdev_tx_timeout( netdevice_t *netdev)
1198 wlandevice_t *wlandev = netdev->ml_priv;
1201 if (wlandev->tx_timeout) {
1202 wlandev->tx_timeout(wlandev);
1204 WLAN_LOG_WARNING("Implement tx_timeout for %s\n",
1206 netif_wake_queue(wlandev->netdev);