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 */
88 #include "wlan_compat.h"
89 #include "p80211types.h"
90 #include "p80211hdr.h"
91 #include "p80211conv.h"
92 #include "p80211mgmt.h"
93 #include "p80211msg.h"
94 #include "p80211netdev.h"
95 #include "p80211ioctl.h"
96 #include "p80211req.h"
97 #include "p80211metastruct.h"
98 #include "p80211metadef.h"
100 /*================================================================*/
101 /* Local Constants */
103 /*================================================================*/
107 /*================================================================*/
110 /*================================================================*/
111 /* Local Static Definitions */
113 #define __NO_VERSION__ /* prevent the static definition */
115 /*================================================================*/
116 /* Local Function Declarations */
118 /* Support functions */
119 static void p80211netdev_rx_bh(unsigned long arg
);
121 /* netdevice method functions */
122 static int p80211knetdev_init( netdevice_t
*netdev
);
123 static struct net_device_stats
* p80211knetdev_get_stats(netdevice_t
*netdev
);
124 static int p80211knetdev_open( netdevice_t
*netdev
);
125 static int p80211knetdev_stop( netdevice_t
*netdev
);
126 static int p80211knetdev_hard_start_xmit( struct sk_buff
*skb
, netdevice_t
*netdev
);
127 static void p80211knetdev_set_multicast_list(netdevice_t
*dev
);
128 static int p80211knetdev_do_ioctl(netdevice_t
*dev
, struct ifreq
*ifr
, int cmd
);
129 static int p80211knetdev_set_mac_address(netdevice_t
*dev
, void *addr
);
130 static void p80211knetdev_tx_timeout(netdevice_t
*netdev
);
131 static int p80211_rx_typedrop( wlandevice_t
*wlandev
, u16 fc
);
134 /*================================================================*/
135 /* Function Definitions */
137 /*----------------------------------------------------------------
138 * p80211knetdev_startup
140 * Initialize the wlandevice/netdevice part of 802.11 services at
148 ----------------------------------------------------------------*/
149 void p80211netdev_startup(void)
157 /*----------------------------------------------------------------
158 * p80211knetdev_shutdown
160 * Shutdown the wlandevice/netdevice part of 802.11 services at
168 ----------------------------------------------------------------*/
170 p80211netdev_shutdown(void)
176 /*----------------------------------------------------------------
179 * Init method for a Linux netdevice. Called in response to
187 ----------------------------------------------------------------*/
188 static int p80211knetdev_init( netdevice_t
*netdev
)
191 /* Called in response to register_netdev */
192 /* This is usually the probe function, but the probe has */
193 /* already been done by the MSD and the create_kdev */
194 /* function. All we do here is return success */
200 /*----------------------------------------------------------------
201 * p80211knetdev_get_stats
203 * Statistics retrieval for linux netdevices. Here we're reporting
204 * the Linux i/f level statistics. Hence, for the primary numbers,
205 * we don't want to report the numbers from the MIB. Eventually,
206 * it might be useful to collect some of the error counters though.
209 * netdev Linux netdevice
212 * the address of the statistics structure
213 ----------------------------------------------------------------*/
214 static struct net_device_stats
*
215 p80211knetdev_get_stats(netdevice_t
*netdev
)
217 wlandevice_t
*wlandev
= netdev
->ml_priv
;
220 /* TODO: review the MIB stats for items that correspond to
224 return &(wlandev
->linux_stats
);
228 /*----------------------------------------------------------------
231 * Linux netdevice open method. Following a successful call here,
232 * the device is supposed to be ready for tx and rx. In our
233 * situation that may not be entirely true due to the state of the
237 * netdev Linux network device structure
240 * zero on success, non-zero otherwise
241 ----------------------------------------------------------------*/
242 static int p80211knetdev_open( netdevice_t
*netdev
)
244 int result
= 0; /* success */
245 wlandevice_t
*wlandev
= netdev
->ml_priv
;
249 /* Check to make sure the MSD is running */
250 if ( wlandev
->msdstate
!= WLAN_MSD_RUNNING
) {
254 /* Tell the MSD to open */
255 if ( wlandev
->open
!= NULL
) {
256 result
= wlandev
->open(wlandev
);
258 p80211netdev_start_queue(wlandev
);
259 wlandev
->state
= WLAN_DEVICE_OPEN
;
270 /*----------------------------------------------------------------
273 * Linux netdevice stop (close) method. Following this call,
274 * no frames should go up or down through this interface.
277 * netdev Linux network device structure
280 * zero on success, non-zero otherwise
281 ----------------------------------------------------------------*/
282 static int p80211knetdev_stop( netdevice_t
*netdev
)
285 wlandevice_t
*wlandev
= netdev
->ml_priv
;
289 if ( wlandev
->close
!= NULL
) {
290 result
= wlandev
->close(wlandev
);
293 p80211netdev_stop_queue(wlandev
);
294 wlandev
->state
= WLAN_DEVICE_CLOSED
;
300 /*----------------------------------------------------------------
303 * Frame receive function called by the mac specific driver.
306 * wlandev WLAN network device structure
307 * skb skbuff containing a full 802.11 frame.
312 ----------------------------------------------------------------*/
314 p80211netdev_rx(wlandevice_t
*wlandev
, struct sk_buff
*skb
)
318 /* Enqueue for post-irq processing */
319 skb_queue_tail(&wlandev
->nsd_rxq
, skb
);
321 tasklet_schedule(&wlandev
->rx_bh
);
327 /*----------------------------------------------------------------
330 * Deferred processing of all received frames.
333 * wlandev WLAN network device structure
334 * skb skbuff containing a full 802.11 frame.
339 ----------------------------------------------------------------*/
340 static void p80211netdev_rx_bh(unsigned long arg
)
342 wlandevice_t
*wlandev
= (wlandevice_t
*) arg
;
343 struct sk_buff
*skb
= NULL
;
344 netdevice_t
*dev
= wlandev
->netdev
;
345 p80211_hdr_a3_t
*hdr
;
350 /* Let's empty our our queue */
351 while ( (skb
= skb_dequeue(&wlandev
->nsd_rxq
)) ) {
352 if (wlandev
->state
== WLAN_DEVICE_OPEN
) {
354 if (dev
->type
!= ARPHRD_ETHER
) {
355 /* RAW frame; we shouldn't convert it */
356 // XXX Append the Prism Header here instead.
358 /* set up various data fields */
360 skb_reset_mac_header(skb
);
361 skb
->ip_summed
= CHECKSUM_NONE
;
362 skb
->pkt_type
= PACKET_OTHERHOST
;
363 skb
->protocol
= htons(ETH_P_80211_RAW
);
364 dev
->last_rx
= jiffies
;
366 wlandev
->linux_stats
.rx_packets
++;
367 wlandev
->linux_stats
.rx_bytes
+= skb
->len
;
371 hdr
= (p80211_hdr_a3_t
*)skb
->data
;
372 fc
= ieee2host16(hdr
->fc
);
373 if (p80211_rx_typedrop(wlandev
, fc
)) {
378 /* perform mcast filtering */
379 if (wlandev
->netdev
->flags
& IFF_ALLMULTI
) {
380 /* allow my local address through */
381 if (memcmp(hdr
->a1
, wlandev
->netdev
->dev_addr
, WLAN_ADDR_LEN
) != 0) {
382 /* but reject anything else that isn't multicast */
383 if (!(hdr
->a1
[0] & 0x01)) {
390 if ( skb_p80211_to_ether(wlandev
, wlandev
->ethconv
, skb
) == 0 ) {
391 skb
->dev
->last_rx
= jiffies
;
392 wlandev
->linux_stats
.rx_packets
++;
393 wlandev
->linux_stats
.rx_bytes
+= skb
->len
;
397 WLAN_LOG_DEBUG(1, "p80211_to_ether failed.\n");
407 /*----------------------------------------------------------------
408 * p80211knetdev_hard_start_xmit
410 * Linux netdevice method for transmitting a frame.
413 * skb Linux sk_buff containing the frame.
414 * netdev Linux netdevice.
417 * If the lower layers report that buffers are full. netdev->tbusy
418 * will be set to prevent higher layers from sending more traffic.
420 * Note: If this function returns non-zero, higher layers retain
421 * ownership of the skb.
424 * zero on success, non-zero on failure.
425 ----------------------------------------------------------------*/
426 static int p80211knetdev_hard_start_xmit( struct sk_buff
*skb
, netdevice_t
*netdev
)
430 wlandevice_t
*wlandev
= netdev
->ml_priv
;
431 p80211_hdr_t p80211_hdr
;
432 p80211_metawep_t p80211_wep
;
440 if (wlandev
->state
!= WLAN_DEVICE_OPEN
) {
445 memset(&p80211_hdr
, 0, sizeof(p80211_hdr_t
));
446 memset(&p80211_wep
, 0, sizeof(p80211_metawep_t
));
448 if ( netif_queue_stopped(netdev
) ) {
449 WLAN_LOG_DEBUG(1, "called when queue stopped.\n");
454 netif_stop_queue(netdev
);
456 /* Check to see that a valid mode is set */
457 switch( wlandev
->macmode
) {
458 case WLAN_MACMODE_IBSS_STA
:
459 case WLAN_MACMODE_ESS_STA
:
460 case WLAN_MACMODE_ESS_AP
:
463 /* Mode isn't set yet, just drop the frame
464 * and return success .
465 * TODO: we need a saner way to handle this
467 if(skb
->protocol
!= ETH_P_80211_RAW
) {
468 p80211netdev_start_queue(wlandev
);
470 "Tx attempt prior to association, frame dropped.\n");
471 wlandev
->linux_stats
.tx_dropped
++;
478 /* Check for raw transmits */
479 if(skb
->protocol
== ETH_P_80211_RAW
) {
480 if (!capable(CAP_NET_ADMIN
)) {
484 /* move the header over */
485 memcpy(&p80211_hdr
, skb
->data
, sizeof(p80211_hdr_t
));
486 skb_pull(skb
, sizeof(p80211_hdr_t
));
488 if ( skb_ether_to_p80211(wlandev
, wlandev
->ethconv
, skb
, &p80211_hdr
, &p80211_wep
) != 0 ) {
490 WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n",
496 if ( wlandev
->txframe
== NULL
) {
501 netdev
->trans_start
= jiffies
;
503 wlandev
->linux_stats
.tx_packets
++;
504 /* count only the packet payload */
505 wlandev
->linux_stats
.tx_bytes
+= skb
->len
;
507 txresult
= wlandev
->txframe(wlandev
, skb
, &p80211_hdr
, &p80211_wep
);
509 if ( txresult
== 0) {
510 /* success and more buf */
511 /* avail, re: hw_txdata */
512 p80211netdev_wake_queue(wlandev
);
514 } else if ( txresult
== 1 ) {
515 /* success, no more avail */
516 WLAN_LOG_DEBUG(3, "txframe success, no more bufs\n");
517 /* netdev->tbusy = 1; don't set here, irqhdlr */
518 /* may have already cleared it */
520 } else if ( txresult
== 2 ) {
521 /* alloc failure, drop frame */
522 WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");
525 /* buffer full or queue busy, drop frame. */
526 WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");
531 /* Free up the WEP buffer if it's not the same as the skb */
532 if ((p80211_wep
.data
) && (p80211_wep
.data
!= skb
->data
))
533 kfree(p80211_wep
.data
);
535 /* we always free the skb here, never in a lower level. */
544 /*----------------------------------------------------------------
545 * p80211knetdev_set_multicast_list
547 * Called from higher lavers whenever there's a need to set/clear
548 * promiscuous mode or rewrite the multicast list.
555 ----------------------------------------------------------------*/
556 static void p80211knetdev_set_multicast_list(netdevice_t
*dev
)
558 wlandevice_t
*wlandev
= dev
->ml_priv
;
562 /* TODO: real multicast support as well */
564 if (wlandev
->set_multicast_list
)
565 wlandev
->set_multicast_list(wlandev
, dev
);
572 static int p80211netdev_ethtool(wlandevice_t
*wlandev
, void __user
*useraddr
)
575 struct ethtool_drvinfo info
;
576 struct ethtool_value edata
;
578 memset(&info
, 0, sizeof(info
));
579 memset(&edata
, 0, sizeof(edata
));
581 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
585 case ETHTOOL_GDRVINFO
:
587 snprintf(info
.driver
, sizeof(info
.driver
), "p80211_%s",
589 snprintf(info
.version
, sizeof(info
.version
), "%s",
595 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
602 if (wlandev
->linkstatus
&&
603 (wlandev
->macmode
!= WLAN_MACMODE_NONE
)) {
609 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
620 /*----------------------------------------------------------------
621 * p80211knetdev_do_ioctl
623 * Handle an ioctl call on one of our devices. Everything Linux
624 * ioctl specific is done here. Then we pass the contents of the
625 * ifr->data to the request message handler.
628 * dev Linux kernel netdevice
629 * ifr Our private ioctl request structure, typed for the
630 * generic struct ifreq so we can use ptr to func
634 * zero on success, a negative errno on failure. Possible values:
635 * -ENETDOWN Device isn't up.
636 * -EBUSY cmd already in progress
637 * -ETIME p80211 cmd timed out (MSD may have its own timers)
638 * -EFAULT memory fault copying msg from user buffer
639 * -ENOMEM unable to allocate kernel msg buffer
640 * -ENOSYS bad magic, it the cmd really for us?
641 * -EintR sleeping on cmd, awakened by signal, cmd cancelled.
644 * Process thread (ioctl caller). TODO: SMP support may require
646 ----------------------------------------------------------------*/
647 static int p80211knetdev_do_ioctl(netdevice_t
*dev
, struct ifreq
*ifr
, int cmd
)
650 p80211ioctl_req_t
*req
= (p80211ioctl_req_t
*)ifr
;
651 wlandevice_t
*wlandev
= dev
->ml_priv
;
655 WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd
, req
->len
);
658 if (cmd
== SIOCETHTOOL
) {
659 result
= p80211netdev_ethtool(wlandev
, (void __user
*) ifr
->ifr_data
);
664 /* Test the magic, assume ifr is good if it's there */
665 if ( req
->magic
!= P80211_IOCTL_MAGIC
) {
670 if ( cmd
== P80211_IFTEST
) {
673 } else if ( cmd
!= P80211_IFREQ
) {
678 /* Allocate a buf of size req->len */
679 if ((msgbuf
= kmalloc( req
->len
, GFP_KERNEL
))) {
680 if ( copy_from_user( msgbuf
, (void __user
*) req
->data
, req
->len
) ) {
683 result
= p80211req_dorequest( wlandev
, msgbuf
);
687 if ( copy_to_user( (void __user
*) req
->data
, msgbuf
, req
->len
)) {
698 return result
; /* If allocate,copyfrom or copyto fails, return errno */
701 /*----------------------------------------------------------------
702 * p80211knetdev_set_mac_address
704 * Handles the ioctl for changing the MACAddress of a netdevice
706 * references: linux/netdevice.h and drivers/net/net_init.c
708 * NOTE: [MSM] We only prevent address changes when the netdev is
709 * up. We don't control anything based on dot11 state. If the
710 * address is changed on a STA that's currently associated, you
711 * will probably lose the ability to send and receive data frames.
712 * Just be aware. Therefore, this should usually only be done
713 * prior to scan/join/auth/assoc.
716 * dev netdevice struct
717 * addr the new MACAddress (a struct)
720 * zero on success, a negative errno on failure. Possible values:
721 * -EBUSY device is bussy (cmd not possible)
722 * -and errors returned by: p80211req_dorequest(..)
724 * by: Collin R. Mulliner <collin@mulliner.org>
725 ----------------------------------------------------------------*/
726 static int p80211knetdev_set_mac_address(netdevice_t
*dev
, void *addr
)
728 struct sockaddr
*new_addr
= addr
;
729 p80211msg_dot11req_mibset_t dot11req
;
730 p80211item_unk392_t
*mibattr
;
731 p80211item_pstr6_t
*macaddr
;
732 p80211item_uint32_t
*resultcode
;
736 /* If we're running, we don't allow MAC address changes */
737 if (netif_running(dev
)) {
741 /* Set up some convenience pointers. */
742 mibattr
= &dot11req
.mibattribute
;
743 macaddr
= (p80211item_pstr6_t
*)&mibattr
->data
;
744 resultcode
= &dot11req
.resultcode
;
746 /* Set up a dot11req_mibset */
747 memset(&dot11req
, 0, sizeof(p80211msg_dot11req_mibset_t
));
748 dot11req
.msgcode
= DIDmsg_dot11req_mibset
;
749 dot11req
.msglen
= sizeof(p80211msg_dot11req_mibset_t
);
750 memcpy(dot11req
.devname
,
751 ((wlandevice_t
*)dev
->ml_priv
)->name
,
752 WLAN_DEVNAMELEN_MAX
- 1);
754 /* Set up the mibattribute argument */
755 mibattr
->did
= DIDmsg_dot11req_mibset_mibattribute
;
756 mibattr
->status
= P80211ENUM_msgitem_status_data_ok
;
757 mibattr
->len
= sizeof(mibattr
->data
);
759 macaddr
->did
= DIDmib_dot11mac_dot11OperationTable_dot11MACAddress
;
760 macaddr
->status
= P80211ENUM_msgitem_status_data_ok
;
761 macaddr
->len
= sizeof(macaddr
->data
);
762 macaddr
->data
.len
= WLAN_ADDR_LEN
;
763 memcpy(&macaddr
->data
.data
, new_addr
->sa_data
, WLAN_ADDR_LEN
);
765 /* Set up the resultcode argument */
766 resultcode
->did
= DIDmsg_dot11req_mibset_resultcode
;
767 resultcode
->status
= P80211ENUM_msgitem_status_no_value
;
768 resultcode
->len
= sizeof(resultcode
->data
);
769 resultcode
->data
= 0;
771 /* now fire the request */
772 result
= p80211req_dorequest(dev
->ml_priv
, (u8
*)&dot11req
);
774 /* If the request wasn't successful, report an error and don't
775 * change the netdev address
777 if ( result
!= 0 || resultcode
->data
!= P80211ENUM_resultcode_success
) {
779 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
780 result
= -EADDRNOTAVAIL
;
782 /* everything's ok, change the addr in netdev */
783 memcpy(dev
->dev_addr
, new_addr
->sa_data
, dev
->addr_len
);
790 static int wlan_change_mtu(netdevice_t
*dev
, int new_mtu
)
793 // 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
794 // and another 8 for wep.
795 if ( (new_mtu
< 68) || (new_mtu
> (2312 - 20 - 8)))
807 /*----------------------------------------------------------------
810 * Roughly matches the functionality of ether_setup. Here
811 * we set up any members of the wlandevice structure that are common
812 * to all devices. Additionally, we allocate a linux 'struct device'
813 * and perform the same setup as ether_setup.
815 * Note: It's important that the caller have setup the wlandev->name
816 * ptr prior to calling this function.
819 * wlandev ptr to the wlandev structure for the
822 * zero on success, non-zero otherwise.
824 * Should be process thread. We'll assume it might be
825 * interrupt though. When we add support for statically
826 * compiled drivers, this function will be called in the
827 * context of the kernel startup code.
828 ----------------------------------------------------------------*/
829 int wlan_setup(wlandevice_t
*wlandev
)
836 /* Set up the wlandev */
837 wlandev
->state
= WLAN_DEVICE_CLOSED
;
838 wlandev
->ethconv
= WLAN_ETHCONV_8021h
;
839 wlandev
->macmode
= WLAN_MACMODE_NONE
;
841 /* Set up the rx queue */
842 skb_queue_head_init(&wlandev
->nsd_rxq
);
843 tasklet_init(&wlandev
->rx_bh
,
845 (unsigned long)wlandev
);
847 /* Allocate and initialize the struct device */
848 dev
= kmalloc(sizeof(netdevice_t
), GFP_ATOMIC
);
850 WLAN_LOG_ERROR("Failed to alloc netdev.\n");
853 memset( dev
, 0, sizeof(netdevice_t
));
855 wlandev
->netdev
= dev
;
856 dev
->ml_priv
= wlandev
;
857 dev
->hard_start_xmit
= p80211knetdev_hard_start_xmit
;
858 dev
->get_stats
= p80211knetdev_get_stats
;
859 #ifdef HAVE_PRIVATE_IOCTL
860 dev
->do_ioctl
= p80211knetdev_do_ioctl
;
862 #ifdef HAVE_MULTICAST
863 dev
->set_multicast_list
= p80211knetdev_set_multicast_list
;
865 dev
->init
= p80211knetdev_init
;
866 dev
->open
= p80211knetdev_open
;
867 dev
->stop
= p80211knetdev_stop
;
869 #if (WIRELESS_EXT < 21)
870 dev
->get_wireless_stats
= p80211wext_get_wireless_stats
;
872 dev
->wireless_handlers
= &p80211wext_handler_def
;
874 netif_stop_queue(dev
);
875 #ifdef HAVE_CHANGE_MTU
876 dev
->change_mtu
= wlan_change_mtu
;
878 #ifdef HAVE_SET_MAC_ADDR
879 dev
->set_mac_address
= p80211knetdev_set_mac_address
;
881 #ifdef HAVE_TX_TIMEOUT
882 dev
->tx_timeout
= &p80211knetdev_tx_timeout
;
883 dev
->watchdog_timeo
= (wlan_watchdog
* HZ
) / 1000;
885 netif_carrier_off(dev
);
892 /*----------------------------------------------------------------
895 * This function is paired with the wlan_setup routine. It should
896 * be called after unregister_wlandev. Basically, all it does is
897 * free the 'struct device' that's associated with the wlandev.
898 * We do it here because the 'struct device' isn't allocated
899 * explicitly in the driver code, it's done in wlan_setup. To
900 * do the free in the driver might seem like 'magic'.
903 * wlandev ptr to the wlandev structure for the
906 * zero on success, non-zero otherwise.
908 * Should be process thread. We'll assume it might be
909 * interrupt though. When we add support for statically
910 * compiled drivers, this function will be called in the
911 * context of the kernel startup code.
912 ----------------------------------------------------------------*/
913 int wlan_unsetup(wlandevice_t
*wlandev
)
919 tasklet_kill(&wlandev
->rx_bh
);
921 if (wlandev
->netdev
== NULL
) {
922 WLAN_LOG_ERROR("called without wlandev->netdev set.\n");
925 free_netdev(wlandev
->netdev
);
926 wlandev
->netdev
= NULL
;
935 /*----------------------------------------------------------------
938 * Roughly matches the functionality of register_netdev. This function
939 * is called after the driver has successfully probed and set up the
940 * resources for the device. It's now ready to become a named device
941 * in the Linux system.
943 * First we allocate a name for the device (if not already set), then
944 * we call the Linux function register_netdevice.
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 register_wlandev(wlandevice_t
*wlandev
)
957 netdevice_t
*dev
= wlandev
->netdev
;
961 i
= dev_alloc_name(wlandev
->netdev
, "wlan%d");
963 i
= register_netdev(wlandev
->netdev
);
969 strcpy(wlandev
->name
, dev
->name
);
976 /*----------------------------------------------------------------
979 * Roughly matches the functionality of unregister_netdev. This
980 * function is called to remove a named device from the system.
982 * First we tell linux that the device should no longer exist.
983 * Then we remove it from the list of known wlan devices.
986 * wlandev ptr to the wlandev structure for the
989 * zero on success, non-zero otherwise.
991 * Can be either interrupt or not.
992 ----------------------------------------------------------------*/
993 int unregister_wlandev(wlandevice_t
*wlandev
)
999 unregister_netdev(wlandev
->netdev
);
1001 /* Now to clean out the rx queue */
1002 while ( (skb
= skb_dequeue(&wlandev
->nsd_rxq
)) ) {
1011 /*----------------------------------------------------------------
1012 * p80211netdev_hwremoved
1014 * Hardware removed notification. This function should be called
1015 * immediately after an MSD has detected that the underlying hardware
1016 * has been yanked out from under us. The primary things we need
1018 * - Mark the wlandev
1019 * - Prevent any further traffic from the knetdev i/f
1020 * - Prevent any further requests from mgmt i/f
1021 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
1023 * - Call the MSD hwremoved function.
1025 * The remainder of the cleanup will be handled by unregister().
1026 * Our primary goal here is to prevent as much tickling of the MSD
1027 * as possible since the MSD is already in a 'wounded' state.
1029 * TODO: As new features are added, this function should be
1033 * wlandev WLAN network device structure
1039 * Usually interrupt.
1040 ----------------------------------------------------------------*/
1041 void p80211netdev_hwremoved(wlandevice_t
*wlandev
)
1044 wlandev
->hwremoved
= 1;
1045 if ( wlandev
->state
== WLAN_DEVICE_OPEN
) {
1046 p80211netdev_stop_queue(wlandev
);
1049 netif_device_detach(wlandev
->netdev
);
1055 /*----------------------------------------------------------------
1056 * p80211_rx_typedrop
1058 * Classifies the frame, increments the appropriate counter, and
1059 * returns 0|1|2 indicating whether the driver should handle, ignore, or
1063 * wlandev wlan device structure
1064 * fc frame control field
1067 * zero if the frame should be handled by the driver,
1068 * one if the frame should be ignored
1069 * anything else means we drop it.
1075 ----------------------------------------------------------------*/
1076 static int p80211_rx_typedrop( wlandevice_t
*wlandev
, u16 fc
)
1081 /* Classify frame, increment counter */
1082 ftype
= WLAN_GET_FC_FTYPE(fc
);
1083 fstype
= WLAN_GET_FC_FSTYPE(fc
);
1086 "rx_typedrop : ftype=%d fstype=%d.\n", ftype
, fstype
);
1089 case WLAN_FTYPE_MGMT
:
1090 if ((wlandev
->netdev
->flags
& IFF_PROMISC
) ||
1091 (wlandev
->netdev
->flags
& IFF_ALLMULTI
)) {
1095 WLAN_LOG_DEBUG(3, "rx'd mgmt:\n");
1098 case WLAN_FSTYPE_ASSOCREQ
:
1099 /* printk("assocreq"); */
1100 wlandev
->rx
.assocreq
++;
1102 case WLAN_FSTYPE_ASSOCRESP
:
1103 /* printk("assocresp"); */
1104 wlandev
->rx
.assocresp
++;
1106 case WLAN_FSTYPE_REASSOCREQ
:
1107 /* printk("reassocreq"); */
1108 wlandev
->rx
.reassocreq
++;
1110 case WLAN_FSTYPE_REASSOCRESP
:
1111 /* printk("reassocresp"); */
1112 wlandev
->rx
.reassocresp
++;
1114 case WLAN_FSTYPE_PROBEREQ
:
1115 /* printk("probereq"); */
1116 wlandev
->rx
.probereq
++;
1118 case WLAN_FSTYPE_PROBERESP
:
1119 /* printk("proberesp"); */
1120 wlandev
->rx
.proberesp
++;
1122 case WLAN_FSTYPE_BEACON
:
1123 /* printk("beacon"); */
1124 wlandev
->rx
.beacon
++;
1126 case WLAN_FSTYPE_ATIM
:
1127 /* printk("atim"); */
1130 case WLAN_FSTYPE_DISASSOC
:
1131 /* printk("disassoc"); */
1132 wlandev
->rx
.disassoc
++;
1134 case WLAN_FSTYPE_AUTHEN
:
1135 /* printk("authen"); */
1136 wlandev
->rx
.authen
++;
1138 case WLAN_FSTYPE_DEAUTHEN
:
1139 /* printk("deauthen"); */
1140 wlandev
->rx
.deauthen
++;
1143 /* printk("unknown"); */
1144 wlandev
->rx
.mgmt_unknown
++;
1151 case WLAN_FTYPE_CTL
:
1152 if ((wlandev
->netdev
->flags
& IFF_PROMISC
) ||
1153 (wlandev
->netdev
->flags
& IFF_ALLMULTI
)) {
1157 WLAN_LOG_DEBUG(3, "rx'd ctl:\n");
1160 case WLAN_FSTYPE_PSPOLL
:
1161 /* printk("pspoll"); */
1162 wlandev
->rx
.pspoll
++;
1164 case WLAN_FSTYPE_RTS
:
1165 /* printk("rts"); */
1168 case WLAN_FSTYPE_CTS
:
1169 /* printk("cts"); */
1172 case WLAN_FSTYPE_ACK
:
1173 /* printk("ack"); */
1176 case WLAN_FSTYPE_CFEND
:
1177 /* printk("cfend"); */
1178 wlandev
->rx
.cfend
++;
1180 case WLAN_FSTYPE_CFENDCFACK
:
1181 /* printk("cfendcfack"); */
1182 wlandev
->rx
.cfendcfack
++;
1185 /* printk("unknown"); */
1186 wlandev
->rx
.ctl_unknown
++;
1193 case WLAN_FTYPE_DATA
:
1196 case WLAN_FSTYPE_DATAONLY
:
1197 wlandev
->rx
.dataonly
++;
1199 case WLAN_FSTYPE_DATA_CFACK
:
1200 wlandev
->rx
.data_cfack
++;
1202 case WLAN_FSTYPE_DATA_CFPOLL
:
1203 wlandev
->rx
.data_cfpoll
++;
1205 case WLAN_FSTYPE_DATA_CFACK_CFPOLL
:
1206 wlandev
->rx
.data__cfack_cfpoll
++;
1208 case WLAN_FSTYPE_NULL
:
1209 WLAN_LOG_DEBUG(3, "rx'd data:null\n");
1212 case WLAN_FSTYPE_CFACK
:
1213 WLAN_LOG_DEBUG(3, "rx'd data:cfack\n");
1214 wlandev
->rx
.cfack
++;
1216 case WLAN_FSTYPE_CFPOLL
:
1217 WLAN_LOG_DEBUG(3, "rx'd data:cfpoll\n");
1218 wlandev
->rx
.cfpoll
++;
1220 case WLAN_FSTYPE_CFACK_CFPOLL
:
1221 WLAN_LOG_DEBUG(3, "rx'd data:cfack_cfpoll\n");
1222 wlandev
->rx
.cfack_cfpoll
++;
1225 /* printk("unknown"); */
1226 wlandev
->rx
.data_unknown
++;
1236 void p80211_suspend(wlandevice_t
*wlandev
)
1243 void p80211_resume(wlandevice_t
*wlandev
)
1250 static void p80211knetdev_tx_timeout( netdevice_t
*netdev
)
1252 wlandevice_t
*wlandev
= netdev
->ml_priv
;
1255 if (wlandev
->tx_timeout
) {
1256 wlandev
->tx_timeout(wlandev
);
1258 WLAN_LOG_WARNING("Implement tx_timeout for %s\n",
1260 p80211netdev_wake_queue(wlandev
);