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>
74 #include <asm/bitops.h>
75 #include <asm/uaccess.h>
76 #include <asm/byteorder.h>
79 #include <linux/ethtool.h>
82 #include <net/iw_handler.h>
83 #include <net/net_namespace.h>
85 /*================================================================*/
86 /* 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 Static Definitions */
114 #define __NO_VERSION__ /* prevent the static definition */
116 #ifdef CONFIG_PROC_FS
117 static struct proc_dir_entry *proc_p80211;
120 /*================================================================*/
121 /* Local Function Declarations */
123 /* Support functions */
124 static void p80211netdev_rx_bh(unsigned long arg);
126 /* netdevice method functions */
127 static int p80211knetdev_init( netdevice_t *netdev);
128 static struct net_device_stats* p80211knetdev_get_stats(netdevice_t *netdev);
129 static int p80211knetdev_open( netdevice_t *netdev);
130 static int p80211knetdev_stop( netdevice_t *netdev );
131 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev);
132 static void p80211knetdev_set_multicast_list(netdevice_t *dev);
133 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd);
134 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr);
135 static void p80211knetdev_tx_timeout(netdevice_t *netdev);
136 static int p80211_rx_typedrop( wlandevice_t *wlandev, UINT16 fc);
138 #ifdef CONFIG_PROC_FS
140 p80211netdev_proc_read(
149 /*================================================================*/
150 /* Function Definitions */
152 /*----------------------------------------------------------------
153 * p80211knetdev_startup
155 * Initialize the wlandevice/netdevice part of 802.11 services at
163 ----------------------------------------------------------------*/
164 void p80211netdev_startup(void)
168 #ifdef CONFIG_PROC_FS
169 if (init_net.proc_net != NULL) {
170 proc_p80211 = create_proc_entry(
172 (S_IFDIR|S_IRUGO|S_IXUGO),
180 /*----------------------------------------------------------------
181 * p80211knetdev_shutdown
183 * Shutdown the wlandevice/netdevice part of 802.11 services at
191 ----------------------------------------------------------------*/
193 p80211netdev_shutdown(void)
196 #ifdef CONFIG_PROC_FS
197 if (proc_p80211 != NULL) {
198 remove_proc_entry("p80211", init_net.proc_net);
204 /*----------------------------------------------------------------
207 * Init method for a Linux netdevice. Called in response to
215 ----------------------------------------------------------------*/
216 static int p80211knetdev_init( netdevice_t *netdev)
219 /* Called in response to register_netdev */
220 /* This is usually the probe function, but the probe has */
221 /* already been done by the MSD and the create_kdev */
222 /* function. All we do here is return success */
228 /*----------------------------------------------------------------
229 * p80211knetdev_get_stats
231 * Statistics retrieval for linux netdevices. Here we're reporting
232 * the Linux i/f level statistics. Hence, for the primary numbers,
233 * we don't want to report the numbers from the MIB. Eventually,
234 * it might be useful to collect some of the error counters though.
237 * netdev Linux netdevice
240 * the address of the statistics structure
241 ----------------------------------------------------------------*/
242 static struct net_device_stats*
243 p80211knetdev_get_stats(netdevice_t *netdev)
245 wlandevice_t *wlandev = netdev->ml_priv;
248 /* TODO: review the MIB stats for items that correspond to
252 return &(wlandev->linux_stats);
256 /*----------------------------------------------------------------
259 * Linux netdevice open method. Following a successful call here,
260 * the device is supposed to be ready for tx and rx. In our
261 * situation that may not be entirely true due to the state of the
265 * netdev Linux network device structure
268 * zero on success, non-zero otherwise
269 ----------------------------------------------------------------*/
270 static int p80211knetdev_open( netdevice_t *netdev )
272 int result = 0; /* success */
273 wlandevice_t *wlandev = netdev->ml_priv;
277 /* Check to make sure the MSD is running */
278 if ( wlandev->msdstate != WLAN_MSD_RUNNING ) {
282 /* Tell the MSD to open */
283 if ( wlandev->open != NULL) {
284 result = wlandev->open(wlandev);
286 p80211netdev_start_queue(wlandev);
287 wlandev->state = WLAN_DEVICE_OPEN;
298 /*----------------------------------------------------------------
301 * Linux netdevice stop (close) method. Following this call,
302 * no frames should go up or down through this interface.
305 * netdev Linux network device structure
308 * zero on success, non-zero otherwise
309 ----------------------------------------------------------------*/
310 static int p80211knetdev_stop( netdevice_t *netdev )
313 wlandevice_t *wlandev = netdev->ml_priv;
317 if ( wlandev->close != NULL ) {
318 result = wlandev->close(wlandev);
321 p80211netdev_stop_queue(wlandev);
322 wlandev->state = WLAN_DEVICE_CLOSED;
328 /*----------------------------------------------------------------
331 * Frame receive function called by the mac specific driver.
334 * wlandev WLAN network device structure
335 * skb skbuff containing a full 802.11 frame.
340 ----------------------------------------------------------------*/
342 p80211netdev_rx(wlandevice_t *wlandev, struct sk_buff *skb )
346 /* Enqueue for post-irq processing */
347 skb_queue_tail(&wlandev->nsd_rxq, skb);
349 tasklet_schedule(&wlandev->rx_bh);
355 /*----------------------------------------------------------------
358 * Deferred processing of all received frames.
361 * wlandev WLAN network device structure
362 * skb skbuff containing a full 802.11 frame.
367 ----------------------------------------------------------------*/
368 static void p80211netdev_rx_bh(unsigned long arg)
370 wlandevice_t *wlandev = (wlandevice_t *) arg;
371 struct sk_buff *skb = NULL;
372 netdevice_t *dev = wlandev->netdev;
373 p80211_hdr_a3_t *hdr;
378 /* Let's empty our our queue */
379 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
380 if (wlandev->state == WLAN_DEVICE_OPEN) {
382 if (dev->type != ARPHRD_ETHER) {
383 /* RAW frame; we shouldn't convert it */
384 // XXX Append the Prism Header here instead.
386 /* set up various data fields */
388 skb_reset_mac_header(skb);
389 skb->ip_summed = CHECKSUM_NONE;
390 skb->pkt_type = PACKET_OTHERHOST;
391 skb->protocol = htons(ETH_P_80211_RAW);
392 dev->last_rx = jiffies;
394 wlandev->linux_stats.rx_packets++;
395 wlandev->linux_stats.rx_bytes += skb->len;
399 hdr = (p80211_hdr_a3_t *)skb->data;
400 fc = ieee2host16(hdr->fc);
401 if (p80211_rx_typedrop(wlandev, fc)) {
406 /* perform mcast filtering */
407 if (wlandev->netdev->flags & IFF_ALLMULTI) {
408 /* allow my local address through */
409 if (memcmp(hdr->a1, wlandev->netdev->dev_addr, WLAN_ADDR_LEN) != 0) {
410 /* but reject anything else that isn't multicast */
411 if (!(hdr->a1[0] & 0x01)) {
418 if ( skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0 ) {
419 skb->dev->last_rx = jiffies;
420 wlandev->linux_stats.rx_packets++;
421 wlandev->linux_stats.rx_bytes += skb->len;
425 WLAN_LOG_DEBUG(1, "p80211_to_ether failed.\n");
435 /*----------------------------------------------------------------
436 * p80211knetdev_hard_start_xmit
438 * Linux netdevice method for transmitting a frame.
441 * skb Linux sk_buff containing the frame.
442 * netdev Linux netdevice.
445 * If the lower layers report that buffers are full. netdev->tbusy
446 * will be set to prevent higher layers from sending more traffic.
448 * Note: If this function returns non-zero, higher layers retain
449 * ownership of the skb.
452 * zero on success, non-zero on failure.
453 ----------------------------------------------------------------*/
454 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev)
458 wlandevice_t *wlandev = netdev->ml_priv;
459 p80211_hdr_t p80211_hdr;
460 p80211_metawep_t p80211_wep;
468 if (wlandev->state != WLAN_DEVICE_OPEN) {
473 memset(&p80211_hdr, 0, sizeof(p80211_hdr_t));
474 memset(&p80211_wep, 0, sizeof(p80211_metawep_t));
476 if ( netif_queue_stopped(netdev) ) {
477 WLAN_LOG_DEBUG(1, "called when queue stopped.\n");
482 netif_stop_queue(netdev);
484 /* Check to see that a valid mode is set */
485 switch( wlandev->macmode ) {
486 case WLAN_MACMODE_IBSS_STA:
487 case WLAN_MACMODE_ESS_STA:
488 case WLAN_MACMODE_ESS_AP:
491 /* Mode isn't set yet, just drop the frame
492 * and return success .
493 * TODO: we need a saner way to handle this
495 if(skb->protocol != ETH_P_80211_RAW) {
496 p80211netdev_start_queue(wlandev);
498 "Tx attempt prior to association, frame dropped.\n");
499 wlandev->linux_stats.tx_dropped++;
506 /* Check for raw transmits */
507 if(skb->protocol == ETH_P_80211_RAW) {
508 if (!capable(CAP_NET_ADMIN)) {
512 /* move the header over */
513 memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));
514 skb_pull(skb, sizeof(p80211_hdr_t));
516 if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {
518 WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n",
524 if ( wlandev->txframe == NULL ) {
529 netdev->trans_start = jiffies;
531 wlandev->linux_stats.tx_packets++;
532 /* count only the packet payload */
533 wlandev->linux_stats.tx_bytes += skb->len;
535 txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);
537 if ( txresult == 0) {
538 /* success and more buf */
539 /* avail, re: hw_txdata */
540 p80211netdev_wake_queue(wlandev);
542 } else if ( txresult == 1 ) {
543 /* success, no more avail */
544 WLAN_LOG_DEBUG(3, "txframe success, no more bufs\n");
545 /* netdev->tbusy = 1; don't set here, irqhdlr */
546 /* may have already cleared it */
548 } else if ( txresult == 2 ) {
549 /* alloc failure, drop frame */
550 WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");
553 /* buffer full or queue busy, drop frame. */
554 WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");
559 /* Free up the WEP buffer if it's not the same as the skb */
560 if ((p80211_wep.data) && (p80211_wep.data != skb->data))
561 kfree(p80211_wep.data);
563 /* we always free the skb here, never in a lower level. */
572 /*----------------------------------------------------------------
573 * p80211knetdev_set_multicast_list
575 * Called from higher lavers whenever there's a need to set/clear
576 * promiscuous mode or rewrite the multicast list.
583 ----------------------------------------------------------------*/
584 static void p80211knetdev_set_multicast_list(netdevice_t *dev)
586 wlandevice_t *wlandev = dev->ml_priv;
590 /* TODO: real multicast support as well */
592 if (wlandev->set_multicast_list)
593 wlandev->set_multicast_list(wlandev, dev);
600 static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
603 struct ethtool_drvinfo info;
604 struct ethtool_value edata;
606 memset(&info, 0, sizeof(info));
607 memset(&edata, 0, sizeof(edata));
609 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
613 case ETHTOOL_GDRVINFO:
615 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
617 snprintf(info.version, sizeof(info.version), "%s",
623 if (copy_to_user(useraddr, &info, sizeof(info)))
630 if (wlandev->linkstatus &&
631 (wlandev->macmode != WLAN_MACMODE_NONE)) {
637 if (copy_to_user(useraddr, &edata, sizeof(edata)))
648 /*----------------------------------------------------------------
649 * p80211knetdev_do_ioctl
651 * Handle an ioctl call on one of our devices. Everything Linux
652 * ioctl specific is done here. Then we pass the contents of the
653 * ifr->data to the request message handler.
656 * dev Linux kernel netdevice
657 * ifr Our private ioctl request structure, typed for the
658 * generic struct ifreq so we can use ptr to func
662 * zero on success, a negative errno on failure. Possible values:
663 * -ENETDOWN Device isn't up.
664 * -EBUSY cmd already in progress
665 * -ETIME p80211 cmd timed out (MSD may have its own timers)
666 * -EFAULT memory fault copying msg from user buffer
667 * -ENOMEM unable to allocate kernel msg buffer
668 * -ENOSYS bad magic, it the cmd really for us?
669 * -EINTR sleeping on cmd, awakened by signal, cmd cancelled.
672 * Process thread (ioctl caller). TODO: SMP support may require
674 ----------------------------------------------------------------*/
675 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd)
678 p80211ioctl_req_t *req = (p80211ioctl_req_t*)ifr;
679 wlandevice_t *wlandev = dev->ml_priv;
683 WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
686 if (cmd == SIOCETHTOOL) {
687 result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);
692 /* Test the magic, assume ifr is good if it's there */
693 if ( req->magic != P80211_IOCTL_MAGIC ) {
698 if ( cmd == P80211_IFTEST ) {
701 } else if ( cmd != P80211_IFREQ ) {
706 /* Allocate a buf of size req->len */
707 if ((msgbuf = kmalloc( req->len, GFP_KERNEL))) {
708 if ( copy_from_user( msgbuf, (void __user *) req->data, req->len) ) {
711 result = p80211req_dorequest( wlandev, msgbuf);
715 if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {
726 return result; /* If allocate,copyfrom or copyto fails, return errno */
729 /*----------------------------------------------------------------
730 * p80211knetdev_set_mac_address
732 * Handles the ioctl for changing the MACAddress of a netdevice
734 * references: linux/netdevice.h and drivers/net/net_init.c
736 * NOTE: [MSM] We only prevent address changes when the netdev is
737 * up. We don't control anything based on dot11 state. If the
738 * address is changed on a STA that's currently associated, you
739 * will probably lose the ability to send and receive data frames.
740 * Just be aware. Therefore, this should usually only be done
741 * prior to scan/join/auth/assoc.
744 * dev netdevice struct
745 * addr the new MACAddress (a struct)
748 * zero on success, a negative errno on failure. Possible values:
749 * -EBUSY device is bussy (cmd not possible)
750 * -and errors returned by: p80211req_dorequest(..)
752 * by: Collin R. Mulliner <collin@mulliner.org>
753 ----------------------------------------------------------------*/
754 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr)
756 struct sockaddr *new_addr = addr;
757 p80211msg_dot11req_mibset_t dot11req;
758 p80211item_unk392_t *mibattr;
759 p80211item_pstr6_t *macaddr;
760 p80211item_uint32_t *resultcode;
764 /* If we're running, we don't allow MAC address changes */
765 if (netif_running(dev)) {
769 /* Set up some convenience pointers. */
770 mibattr = &dot11req.mibattribute;
771 macaddr = (p80211item_pstr6_t*)&mibattr->data;
772 resultcode = &dot11req.resultcode;
774 /* Set up a dot11req_mibset */
775 memset(&dot11req, 0, sizeof(p80211msg_dot11req_mibset_t));
776 dot11req.msgcode = DIDmsg_dot11req_mibset;
777 dot11req.msglen = sizeof(p80211msg_dot11req_mibset_t);
778 memcpy(dot11req.devname,
779 ((wlandevice_t *)dev->ml_priv)->name,
780 WLAN_DEVNAMELEN_MAX - 1);
782 /* Set up the mibattribute argument */
783 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
784 mibattr->status = P80211ENUM_msgitem_status_data_ok;
785 mibattr->len = sizeof(mibattr->data);
787 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;
788 macaddr->status = P80211ENUM_msgitem_status_data_ok;
789 macaddr->len = sizeof(macaddr->data);
790 macaddr->data.len = WLAN_ADDR_LEN;
791 memcpy(&macaddr->data.data, new_addr->sa_data, WLAN_ADDR_LEN);
793 /* Set up the resultcode argument */
794 resultcode->did = DIDmsg_dot11req_mibset_resultcode;
795 resultcode->status = P80211ENUM_msgitem_status_no_value;
796 resultcode->len = sizeof(resultcode->data);
797 resultcode->data = 0;
799 /* now fire the request */
800 result = p80211req_dorequest(dev->ml_priv, (UINT8 *)&dot11req);
802 /* If the request wasn't successful, report an error and don't
803 * change the netdev address
805 if ( result != 0 || resultcode->data != P80211ENUM_resultcode_success) {
807 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
808 result = -EADDRNOTAVAIL;
810 /* everything's ok, change the addr in netdev */
811 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
818 static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
821 // 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
822 // and another 8 for wep.
823 if ( (new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))
835 /*----------------------------------------------------------------
838 * Roughly matches the functionality of ether_setup. Here
839 * we set up any members of the wlandevice structure that are common
840 * to all devices. Additionally, we allocate a linux 'struct device'
841 * and perform the same setup as ether_setup.
843 * Note: It's important that the caller have setup the wlandev->name
844 * ptr prior to calling this function.
847 * wlandev ptr to the wlandev structure for the
850 * zero on success, non-zero otherwise.
852 * Should be process thread. We'll assume it might be
853 * interrupt though. When we add support for statically
854 * compiled drivers, this function will be called in the
855 * context of the kernel startup code.
856 ----------------------------------------------------------------*/
857 int wlan_setup(wlandevice_t *wlandev)
864 /* Set up the wlandev */
865 wlandev->state = WLAN_DEVICE_CLOSED;
866 wlandev->ethconv = WLAN_ETHCONV_8021h;
867 wlandev->macmode = WLAN_MACMODE_NONE;
869 /* Set up the rx queue */
870 skb_queue_head_init(&wlandev->nsd_rxq);
871 tasklet_init(&wlandev->rx_bh,
873 (unsigned long)wlandev);
875 /* Allocate and initialize the struct device */
876 dev = kmalloc(sizeof(netdevice_t), GFP_ATOMIC);
878 WLAN_LOG_ERROR("Failed to alloc netdev.\n");
881 memset( dev, 0, sizeof(netdevice_t));
883 wlandev->netdev = dev;
884 dev->ml_priv = wlandev;
885 dev->hard_start_xmit = p80211knetdev_hard_start_xmit;
886 dev->get_stats = p80211knetdev_get_stats;
887 #ifdef HAVE_PRIVATE_IOCTL
888 dev->do_ioctl = p80211knetdev_do_ioctl;
890 #ifdef HAVE_MULTICAST
891 dev->set_multicast_list = p80211knetdev_set_multicast_list;
893 dev->init = p80211knetdev_init;
894 dev->open = p80211knetdev_open;
895 dev->stop = p80211knetdev_stop;
897 #ifdef CONFIG_NET_WIRELESS
898 #if (WIRELESS_EXT < 21)
899 dev->get_wireless_stats = p80211wext_get_wireless_stats;
901 dev->wireless_handlers = &p80211wext_handler_def;
904 netif_stop_queue(dev);
905 #ifdef HAVE_CHANGE_MTU
906 dev->change_mtu = wlan_change_mtu;
908 #ifdef HAVE_SET_MAC_ADDR
909 dev->set_mac_address = p80211knetdev_set_mac_address;
911 #ifdef HAVE_TX_TIMEOUT
912 dev->tx_timeout = &p80211knetdev_tx_timeout;
913 dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000;
915 netif_carrier_off(dev);
922 /*----------------------------------------------------------------
925 * This function is paired with the wlan_setup routine. It should
926 * be called after unregister_wlandev. Basically, all it does is
927 * free the 'struct device' that's associated with the wlandev.
928 * We do it here because the 'struct device' isn't allocated
929 * explicitly in the driver code, it's done in wlan_setup. To
930 * do the free in the driver might seem like 'magic'.
933 * wlandev ptr to the wlandev structure for the
936 * zero on success, non-zero otherwise.
938 * Should be process thread. We'll assume it might be
939 * interrupt though. When we add support for statically
940 * compiled drivers, this function will be called in the
941 * context of the kernel startup code.
942 ----------------------------------------------------------------*/
943 int wlan_unsetup(wlandevice_t *wlandev)
949 tasklet_kill(&wlandev->rx_bh);
951 if (wlandev->netdev == NULL ) {
952 WLAN_LOG_ERROR("called without wlandev->netdev set.\n");
955 free_netdev(wlandev->netdev);
956 wlandev->netdev = NULL;
965 /*----------------------------------------------------------------
968 * Roughly matches the functionality of register_netdev. This function
969 * is called after the driver has successfully probed and set up the
970 * resources for the device. It's now ready to become a named device
971 * in the Linux system.
973 * First we allocate a name for the device (if not already set), then
974 * we call the Linux function register_netdevice.
977 * wlandev ptr to the wlandev structure for the
980 * zero on success, non-zero otherwise.
982 * Can be either interrupt or not.
983 ----------------------------------------------------------------*/
984 int register_wlandev(wlandevice_t *wlandev)
987 netdevice_t *dev = wlandev->netdev;
991 i = dev_alloc_name(wlandev->netdev, "wlan%d");
993 i = register_netdev(wlandev->netdev);
999 strcpy(wlandev->name, dev->name);
1001 #ifdef CONFIG_PROC_FS
1003 wlandev->procdir = proc_mkdir(wlandev->name, proc_p80211);
1004 if ( wlandev->procdir )
1005 wlandev->procwlandev =
1006 create_proc_read_entry("wlandev", 0,
1008 p80211netdev_proc_read,
1010 if (wlandev->nsd_proc_read)
1011 create_proc_read_entry("nsd", 0,
1013 wlandev->nsd_proc_read,
1023 /*----------------------------------------------------------------
1024 * unregister_wlandev
1026 * Roughly matches the functionality of unregister_netdev. This
1027 * function is called to remove a named device from the system.
1029 * First we tell linux that the device should no longer exist.
1030 * Then we remove it from the list of known wlan devices.
1033 * wlandev ptr to the wlandev structure for the
1036 * zero on success, non-zero otherwise.
1038 * Can be either interrupt or not.
1039 ----------------------------------------------------------------*/
1040 int unregister_wlandev(wlandevice_t *wlandev)
1042 struct sk_buff *skb;
1046 #ifdef CONFIG_PROC_FS
1047 if ( wlandev->procwlandev ) {
1048 remove_proc_entry("wlandev", wlandev->procdir);
1050 if ( wlandev->nsd_proc_read ) {
1051 remove_proc_entry("nsd", wlandev->procdir);
1053 if (wlandev->procdir) {
1054 remove_proc_entry(wlandev->name, proc_p80211);
1058 unregister_netdev(wlandev->netdev);
1060 /* Now to clean out the rx queue */
1061 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
1069 #ifdef CONFIG_PROC_FS
1070 /*----------------------------------------------------------------
1073 * Read function for /proc/net/p80211/<device>/wlandev
1083 * zero on success, non-zero otherwise.
1085 * Can be either interrupt or not.
1086 ----------------------------------------------------------------*/
1088 p80211netdev_proc_read(
1097 wlandevice_t *wlandev = (wlandevice_t *) data;
1105 p += sprintf(p, "p80211 version: %s (%s)\n\n",
1106 WLAN_RELEASE, WLAN_BUILD_DATE);
1107 p += sprintf(p, "name : %s\n", wlandev->name);
1108 p += sprintf(p, "nsd name : %s\n", wlandev->nsdname);
1109 p += sprintf(p, "address : %02x:%02x:%02x:%02x:%02x:%02x\n",
1110 wlandev->netdev->dev_addr[0], wlandev->netdev->dev_addr[1], wlandev->netdev->dev_addr[2],
1111 wlandev->netdev->dev_addr[3], wlandev->netdev->dev_addr[4], wlandev->netdev->dev_addr[5]);
1112 p += sprintf(p, "nsd caps : %s%s%s%s%s%s%s%s%s%s\n",
1113 (wlandev->nsdcaps & P80211_NSDCAP_HARDWAREWEP) ? "wep_hw " : "",
1114 (wlandev->nsdcaps & P80211_NSDCAP_TIEDWEP) ? "wep_tied " : "",
1115 (wlandev->nsdcaps & P80211_NSDCAP_NOHOSTWEP) ? "wep_hw_only " : "",
1116 (wlandev->nsdcaps & P80211_NSDCAP_PBCC) ? "pbcc " : "",
1117 (wlandev->nsdcaps & P80211_NSDCAP_SHORT_PREAMBLE) ? "short_preamble " : "",
1118 (wlandev->nsdcaps & P80211_NSDCAP_AGILITY) ? "agility " : "",
1119 (wlandev->nsdcaps & P80211_NSDCAP_AP_RETRANSMIT) ? "ap_retransmit " : "",
1120 (wlandev->nsdcaps & P80211_NSDCAP_HWFRAGMENT) ? "hw_frag " : "",
1121 (wlandev->nsdcaps & P80211_NSDCAP_AUTOJOIN) ? "autojoin " : "",
1122 (wlandev->nsdcaps & P80211_NSDCAP_NOSCAN) ? "" : "scan ");
1125 p += sprintf(p, "bssid : %02x:%02x:%02x:%02x:%02x:%02x\n",
1126 wlandev->bssid[0], wlandev->bssid[1], wlandev->bssid[2],
1127 wlandev->bssid[3], wlandev->bssid[4], wlandev->bssid[5]);
1129 p += sprintf(p, "Enabled : %s%s\n",
1130 (wlandev->shortpreamble) ? "short_preamble " : "",
1131 (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) ? "privacy" : "");
1140 /*----------------------------------------------------------------
1141 * p80211netdev_hwremoved
1143 * Hardware removed notification. This function should be called
1144 * immediately after an MSD has detected that the underlying hardware
1145 * has been yanked out from under us. The primary things we need
1147 * - Mark the wlandev
1148 * - Prevent any further traffic from the knetdev i/f
1149 * - Prevent any further requests from mgmt i/f
1150 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
1152 * - Call the MSD hwremoved function.
1154 * The remainder of the cleanup will be handled by unregister().
1155 * Our primary goal here is to prevent as much tickling of the MSD
1156 * as possible since the MSD is already in a 'wounded' state.
1158 * TODO: As new features are added, this function should be
1162 * wlandev WLAN network device structure
1168 * Usually interrupt.
1169 ----------------------------------------------------------------*/
1170 void p80211netdev_hwremoved(wlandevice_t *wlandev)
1173 wlandev->hwremoved = 1;
1174 if ( wlandev->state == WLAN_DEVICE_OPEN) {
1175 p80211netdev_stop_queue(wlandev);
1178 netif_device_detach(wlandev->netdev);
1184 /*----------------------------------------------------------------
1185 * p80211_rx_typedrop
1187 * Classifies the frame, increments the appropriate counter, and
1188 * returns 0|1|2 indicating whether the driver should handle, ignore, or
1192 * wlandev wlan device structure
1193 * fc frame control field
1196 * zero if the frame should be handled by the driver,
1197 * one if the frame should be ignored
1198 * anything else means we drop it.
1204 ----------------------------------------------------------------*/
1205 static int p80211_rx_typedrop( wlandevice_t *wlandev, UINT16 fc)
1210 /* Classify frame, increment counter */
1211 ftype = WLAN_GET_FC_FTYPE(fc);
1212 fstype = WLAN_GET_FC_FSTYPE(fc);
1215 "rx_typedrop : ftype=%d fstype=%d.\n", ftype, fstype);
1218 case WLAN_FTYPE_MGMT:
1219 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1220 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1224 WLAN_LOG_DEBUG(3, "rx'd mgmt:\n");
1227 case WLAN_FSTYPE_ASSOCREQ:
1228 /* printk("assocreq"); */
1229 wlandev->rx.assocreq++;
1231 case WLAN_FSTYPE_ASSOCRESP:
1232 /* printk("assocresp"); */
1233 wlandev->rx.assocresp++;
1235 case WLAN_FSTYPE_REASSOCREQ:
1236 /* printk("reassocreq"); */
1237 wlandev->rx.reassocreq++;
1239 case WLAN_FSTYPE_REASSOCRESP:
1240 /* printk("reassocresp"); */
1241 wlandev->rx.reassocresp++;
1243 case WLAN_FSTYPE_PROBEREQ:
1244 /* printk("probereq"); */
1245 wlandev->rx.probereq++;
1247 case WLAN_FSTYPE_PROBERESP:
1248 /* printk("proberesp"); */
1249 wlandev->rx.proberesp++;
1251 case WLAN_FSTYPE_BEACON:
1252 /* printk("beacon"); */
1253 wlandev->rx.beacon++;
1255 case WLAN_FSTYPE_ATIM:
1256 /* printk("atim"); */
1259 case WLAN_FSTYPE_DISASSOC:
1260 /* printk("disassoc"); */
1261 wlandev->rx.disassoc++;
1263 case WLAN_FSTYPE_AUTHEN:
1264 /* printk("authen"); */
1265 wlandev->rx.authen++;
1267 case WLAN_FSTYPE_DEAUTHEN:
1268 /* printk("deauthen"); */
1269 wlandev->rx.deauthen++;
1272 /* printk("unknown"); */
1273 wlandev->rx.mgmt_unknown++;
1280 case WLAN_FTYPE_CTL:
1281 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1282 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1286 WLAN_LOG_DEBUG(3, "rx'd ctl:\n");
1289 case WLAN_FSTYPE_PSPOLL:
1290 /* printk("pspoll"); */
1291 wlandev->rx.pspoll++;
1293 case WLAN_FSTYPE_RTS:
1294 /* printk("rts"); */
1297 case WLAN_FSTYPE_CTS:
1298 /* printk("cts"); */
1301 case WLAN_FSTYPE_ACK:
1302 /* printk("ack"); */
1305 case WLAN_FSTYPE_CFEND:
1306 /* printk("cfend"); */
1307 wlandev->rx.cfend++;
1309 case WLAN_FSTYPE_CFENDCFACK:
1310 /* printk("cfendcfack"); */
1311 wlandev->rx.cfendcfack++;
1314 /* printk("unknown"); */
1315 wlandev->rx.ctl_unknown++;
1322 case WLAN_FTYPE_DATA:
1325 case WLAN_FSTYPE_DATAONLY:
1326 wlandev->rx.dataonly++;
1328 case WLAN_FSTYPE_DATA_CFACK:
1329 wlandev->rx.data_cfack++;
1331 case WLAN_FSTYPE_DATA_CFPOLL:
1332 wlandev->rx.data_cfpoll++;
1334 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1335 wlandev->rx.data__cfack_cfpoll++;
1337 case WLAN_FSTYPE_NULL:
1338 WLAN_LOG_DEBUG(3, "rx'd data:null\n");
1341 case WLAN_FSTYPE_CFACK:
1342 WLAN_LOG_DEBUG(3, "rx'd data:cfack\n");
1343 wlandev->rx.cfack++;
1345 case WLAN_FSTYPE_CFPOLL:
1346 WLAN_LOG_DEBUG(3, "rx'd data:cfpoll\n");
1347 wlandev->rx.cfpoll++;
1349 case WLAN_FSTYPE_CFACK_CFPOLL:
1350 WLAN_LOG_DEBUG(3, "rx'd data:cfack_cfpoll\n");
1351 wlandev->rx.cfack_cfpoll++;
1354 /* printk("unknown"); */
1355 wlandev->rx.data_unknown++;
1365 void p80211_suspend(wlandevice_t *wlandev)
1372 void p80211_resume(wlandevice_t *wlandev)
1379 static void p80211knetdev_tx_timeout( netdevice_t *netdev)
1381 wlandevice_t *wlandev = netdev->ml_priv;
1384 if (wlandev->tx_timeout) {
1385 wlandev->tx_timeout(wlandev);
1387 WLAN_LOG_WARNING("Implement tx_timeout for %s\n",
1389 p80211netdev_wake_queue(wlandev);