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 * --------------------------------------------------------------------
52 #include <linux/module.h>
53 #include <linux/kernel.h>
54 #include <linux/sched.h>
55 #include <linux/types.h>
56 #include <linux/skbuff.h>
57 #include <linux/slab.h>
58 #include <linux/proc_fs.h>
59 #include <linux/interrupt.h>
60 #include <linux/netdevice.h>
61 #include <linux/kmod.h>
62 #include <linux/if_arp.h>
63 #include <linux/wireless.h>
64 #include <linux/sockios.h>
65 #include <linux/etherdevice.h>
66 #include <linux/if_ether.h>
67 #include <linux/byteorder/generic.h>
68 #include <linux/bitops.h>
69 #include <linux/uaccess.h>
70 #include <asm/byteorder.h>
73 #include <linux/ethtool.h>
76 #include <net/iw_handler.h>
77 #include <net/net_namespace.h>
78 #include <net/cfg80211.h>
80 #include "p80211types.h"
81 #include "p80211hdr.h"
82 #include "p80211conv.h"
83 #include "p80211mgmt.h"
84 #include "p80211msg.h"
85 #include "p80211netdev.h"
86 #include "p80211ioctl.h"
87 #include "p80211req.h"
88 #include "p80211metastruct.h"
89 #include "p80211metadef.h"
93 /* netdevice method functions */
94 static int p80211knetdev_init(netdevice_t
*netdev
);
95 static struct net_device_stats
*p80211knetdev_get_stats(netdevice_t
*netdev
);
96 static int p80211knetdev_open(netdevice_t
*netdev
);
97 static int p80211knetdev_stop(netdevice_t
*netdev
);
98 static int p80211knetdev_hard_start_xmit(struct sk_buff
*skb
,
100 static void p80211knetdev_set_multicast_list(netdevice_t
*dev
);
101 static int p80211knetdev_do_ioctl(netdevice_t
*dev
, struct ifreq
*ifr
,
103 static int p80211knetdev_set_mac_address(netdevice_t
*dev
, void *addr
);
104 static void p80211knetdev_tx_timeout(netdevice_t
*netdev
);
105 static int p80211_rx_typedrop(wlandevice_t
*wlandev
, u16 fc
);
107 int wlan_watchdog
= 5000;
108 module_param(wlan_watchdog
, int, 0644);
109 MODULE_PARM_DESC(wlan_watchdog
, "transmit timeout in milliseconds");
111 int wlan_wext_write
= 1;
112 module_param(wlan_wext_write
, int, 0644);
113 MODULE_PARM_DESC(wlan_wext_write
, "enable write wireless extensions");
115 /*----------------------------------------------------------------
118 * Init method for a Linux netdevice. Called in response to
126 ----------------------------------------------------------------*/
127 static int p80211knetdev_init(netdevice_t
*netdev
)
129 /* Called in response to register_netdev */
130 /* This is usually the probe function, but the probe has */
131 /* already been done by the MSD and the create_kdev */
132 /* function. All we do here is return success */
136 /*----------------------------------------------------------------
137 * p80211knetdev_get_stats
139 * Statistics retrieval for linux netdevices. Here we're reporting
140 * the Linux i/f level statistics. Hence, for the primary numbers,
141 * we don't want to report the numbers from the MIB. Eventually,
142 * it might be useful to collect some of the error counters though.
145 * netdev Linux netdevice
148 * the address of the statistics structure
149 ----------------------------------------------------------------*/
150 static struct net_device_stats
*p80211knetdev_get_stats(netdevice_t
*netdev
)
152 wlandevice_t
*wlandev
= netdev
->ml_priv
;
154 /* TODO: review the MIB stats for items that correspond to
157 return &(wlandev
->linux_stats
);
160 /*----------------------------------------------------------------
163 * Linux netdevice open method. Following a successful call here,
164 * the device is supposed to be ready for tx and rx. In our
165 * situation that may not be entirely true due to the state of the
169 * netdev Linux network device structure
172 * zero on success, non-zero otherwise
173 ----------------------------------------------------------------*/
174 static int p80211knetdev_open(netdevice_t
*netdev
)
176 int result
= 0; /* success */
177 wlandevice_t
*wlandev
= netdev
->ml_priv
;
179 /* Check to make sure the MSD is running */
180 if (wlandev
->msdstate
!= WLAN_MSD_RUNNING
)
183 /* Tell the MSD to open */
184 if (wlandev
->open
!= NULL
) {
185 result
= wlandev
->open(wlandev
);
187 netif_start_queue(wlandev
->netdev
);
188 wlandev
->state
= WLAN_DEVICE_OPEN
;
197 /*----------------------------------------------------------------
200 * Linux netdevice stop (close) method. Following this call,
201 * no frames should go up or down through this interface.
204 * netdev Linux network device structure
207 * zero on success, non-zero otherwise
208 ----------------------------------------------------------------*/
209 static int p80211knetdev_stop(netdevice_t
*netdev
)
212 wlandevice_t
*wlandev
= netdev
->ml_priv
;
214 if (wlandev
->close
!= NULL
)
215 result
= wlandev
->close(wlandev
);
217 netif_stop_queue(wlandev
->netdev
);
218 wlandev
->state
= WLAN_DEVICE_CLOSED
;
223 /*----------------------------------------------------------------
226 * Frame receive function called by the mac specific driver.
229 * wlandev WLAN network device structure
230 * skb skbuff containing a full 802.11 frame.
235 ----------------------------------------------------------------*/
236 void p80211netdev_rx(wlandevice_t
*wlandev
, struct sk_buff
*skb
)
238 /* Enqueue for post-irq processing */
239 skb_queue_tail(&wlandev
->nsd_rxq
, skb
);
240 tasklet_schedule(&wlandev
->rx_bh
);
243 #define CONV_TO_ETHER_SKIPPED 0x01
244 #define CONV_TO_ETHER_FAILED 0x02
247 * p80211_convert_to_ether - conversion from 802.11 frame to ethernet frame
248 * @wlandev: pointer to WLAN device
249 * @skb: pointer to socket buffer
251 * Returns: 0 if conversion succeeded
252 * CONV_TO_ETHER_FAILED if conversion failed
253 * CONV_TO_ETHER_SKIPPED if frame is ignored
255 static int p80211_convert_to_ether(wlandevice_t
*wlandev
, struct sk_buff
*skb
)
257 struct p80211_hdr_a3
*hdr
;
259 hdr
= (struct p80211_hdr_a3
*) skb
->data
;
260 if (p80211_rx_typedrop(wlandev
, hdr
->fc
))
261 return CONV_TO_ETHER_SKIPPED
;
263 /* perform mcast filtering: allow my local address through but reject
264 * anything else that isn't multicast
266 if (wlandev
->netdev
->flags
& IFF_ALLMULTI
) {
267 if (!ether_addr_equal_unaligned(wlandev
->netdev
->dev_addr
,
269 if (!is_multicast_ether_addr(hdr
->a1
))
270 return CONV_TO_ETHER_SKIPPED
;
274 if (skb_p80211_to_ether(wlandev
, wlandev
->ethconv
, skb
) == 0) {
275 skb
->dev
->last_rx
= jiffies
;
276 wlandev
->linux_stats
.rx_packets
++;
277 wlandev
->linux_stats
.rx_bytes
+= skb
->len
;
282 netdev_dbg(wlandev
->netdev
, "p80211_convert_to_ether failed.\n");
283 return CONV_TO_ETHER_FAILED
;
287 * p80211netdev_rx_bh - deferred processing of all received frames
289 * @arg: pointer to WLAN network device structure (cast to unsigned long)
291 static void p80211netdev_rx_bh(unsigned long arg
)
293 wlandevice_t
*wlandev
= (wlandevice_t
*) arg
;
294 struct sk_buff
*skb
= NULL
;
295 netdevice_t
*dev
= wlandev
->netdev
;
297 /* Let's empty our our queue */
298 while ((skb
= skb_dequeue(&wlandev
->nsd_rxq
))) {
299 if (wlandev
->state
== WLAN_DEVICE_OPEN
) {
301 if (dev
->type
!= ARPHRD_ETHER
) {
302 /* RAW frame; we shouldn't convert it */
303 /* XXX Append the Prism Header here instead. */
305 /* set up various data fields */
307 skb_reset_mac_header(skb
);
308 skb
->ip_summed
= CHECKSUM_NONE
;
309 skb
->pkt_type
= PACKET_OTHERHOST
;
310 skb
->protocol
= htons(ETH_P_80211_RAW
);
311 dev
->last_rx
= jiffies
;
313 wlandev
->linux_stats
.rx_packets
++;
314 wlandev
->linux_stats
.rx_bytes
+= skb
->len
;
318 if (!p80211_convert_to_ether(wlandev
, skb
))
326 /*----------------------------------------------------------------
327 * p80211knetdev_hard_start_xmit
329 * Linux netdevice method for transmitting a frame.
332 * skb Linux sk_buff containing the frame.
333 * netdev Linux netdevice.
336 * If the lower layers report that buffers are full. netdev->tbusy
337 * will be set to prevent higher layers from sending more traffic.
339 * Note: If this function returns non-zero, higher layers retain
340 * ownership of the skb.
343 * zero on success, non-zero on failure.
344 ----------------------------------------------------------------*/
345 static int p80211knetdev_hard_start_xmit(struct sk_buff
*skb
,
350 wlandevice_t
*wlandev
= netdev
->ml_priv
;
351 union p80211_hdr p80211_hdr
;
352 struct p80211_metawep p80211_wep
;
354 p80211_wep
.data
= NULL
;
359 if (wlandev
->state
!= WLAN_DEVICE_OPEN
) {
364 memset(&p80211_hdr
, 0, sizeof(union p80211_hdr
));
365 memset(&p80211_wep
, 0, sizeof(struct p80211_metawep
));
367 if (netif_queue_stopped(netdev
)) {
368 netdev_dbg(netdev
, "called when queue stopped.\n");
373 netif_stop_queue(netdev
);
375 /* Check to see that a valid mode is set */
376 switch (wlandev
->macmode
) {
377 case WLAN_MACMODE_IBSS_STA
:
378 case WLAN_MACMODE_ESS_STA
:
379 case WLAN_MACMODE_ESS_AP
:
382 /* Mode isn't set yet, just drop the frame
383 * and return success .
384 * TODO: we need a saner way to handle this
386 if (skb
->protocol
!= ETH_P_80211_RAW
) {
387 netif_start_queue(wlandev
->netdev
);
388 netdev_notice(netdev
, "Tx attempt prior to association, frame dropped.\n");
389 wlandev
->linux_stats
.tx_dropped
++;
396 /* Check for raw transmits */
397 if (skb
->protocol
== ETH_P_80211_RAW
) {
398 if (!capable(CAP_NET_ADMIN
)) {
402 /* move the header over */
403 memcpy(&p80211_hdr
, skb
->data
, sizeof(union p80211_hdr
));
404 skb_pull(skb
, sizeof(union p80211_hdr
));
406 if (skb_ether_to_p80211
407 (wlandev
, wlandev
->ethconv
, skb
, &p80211_hdr
,
410 netdev_dbg(netdev
, "ether_to_80211(%d) failed.\n",
416 if (wlandev
->txframe
== NULL
) {
421 netdev
->trans_start
= jiffies
;
423 wlandev
->linux_stats
.tx_packets
++;
424 /* count only the packet payload */
425 wlandev
->linux_stats
.tx_bytes
+= skb
->len
;
427 txresult
= wlandev
->txframe(wlandev
, skb
, &p80211_hdr
, &p80211_wep
);
430 /* success and more buf */
431 /* avail, re: hw_txdata */
432 netif_wake_queue(wlandev
->netdev
);
433 result
= NETDEV_TX_OK
;
434 } else if (txresult
== 1) {
435 /* success, no more avail */
436 netdev_dbg(netdev
, "txframe success, no more bufs\n");
437 /* netdev->tbusy = 1; don't set here, irqhdlr */
438 /* may have already cleared it */
439 result
= NETDEV_TX_OK
;
440 } else if (txresult
== 2) {
441 /* alloc failure, drop frame */
442 netdev_dbg(netdev
, "txframe returned alloc_fail\n");
443 result
= NETDEV_TX_BUSY
;
445 /* buffer full or queue busy, drop frame. */
446 netdev_dbg(netdev
, "txframe returned full or busy\n");
447 result
= NETDEV_TX_BUSY
;
451 /* Free up the WEP buffer if it's not the same as the skb */
452 if ((p80211_wep
.data
) && (p80211_wep
.data
!= skb
->data
))
453 kzfree(p80211_wep
.data
);
455 /* we always free the skb here, never in a lower level. */
462 /*----------------------------------------------------------------
463 * p80211knetdev_set_multicast_list
465 * Called from higher layers whenever there's a need to set/clear
466 * promiscuous mode or rewrite the multicast list.
473 ----------------------------------------------------------------*/
474 static void p80211knetdev_set_multicast_list(netdevice_t
*dev
)
476 wlandevice_t
*wlandev
= dev
->ml_priv
;
478 /* TODO: real multicast support as well */
480 if (wlandev
->set_multicast_list
)
481 wlandev
->set_multicast_list(wlandev
, dev
);
487 static int p80211netdev_ethtool(wlandevice_t
*wlandev
, void __user
*useraddr
)
490 struct ethtool_drvinfo info
;
491 struct ethtool_value edata
;
493 memset(&info
, 0, sizeof(info
));
494 memset(&edata
, 0, sizeof(edata
));
496 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
500 case ETHTOOL_GDRVINFO
:
502 snprintf(info
.driver
, sizeof(info
.driver
), "p80211_%s",
504 snprintf(info
.version
, sizeof(info
.version
), "%s",
507 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
514 if (wlandev
->linkstatus
&&
515 (wlandev
->macmode
!= WLAN_MACMODE_NONE
)) {
521 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
532 /*----------------------------------------------------------------
533 * p80211knetdev_do_ioctl
535 * Handle an ioctl call on one of our devices. Everything Linux
536 * ioctl specific is done here. Then we pass the contents of the
537 * ifr->data to the request message handler.
540 * dev Linux kernel netdevice
541 * ifr Our private ioctl request structure, typed for the
542 * generic struct ifreq so we can use ptr to func
546 * zero on success, a negative errno on failure. Possible values:
547 * -ENETDOWN Device isn't up.
548 * -EBUSY cmd already in progress
549 * -ETIME p80211 cmd timed out (MSD may have its own timers)
550 * -EFAULT memory fault copying msg from user buffer
551 * -ENOMEM unable to allocate kernel msg buffer
552 * -ENOSYS bad magic, it the cmd really for us?
553 * -EintR sleeping on cmd, awakened by signal, cmd cancelled.
556 * Process thread (ioctl caller). TODO: SMP support may require
558 ----------------------------------------------------------------*/
559 static int p80211knetdev_do_ioctl(netdevice_t
*dev
, struct ifreq
*ifr
, int cmd
)
562 struct p80211ioctl_req
*req
= (struct p80211ioctl_req
*) ifr
;
563 wlandevice_t
*wlandev
= dev
->ml_priv
;
566 netdev_dbg(dev
, "rx'd ioctl, cmd=%d, len=%d\n", cmd
, req
->len
);
569 if (cmd
== SIOCETHTOOL
) {
571 p80211netdev_ethtool(wlandev
, (void __user
*)ifr
->ifr_data
);
576 /* Test the magic, assume ifr is good if it's there */
577 if (req
->magic
!= P80211_IOCTL_MAGIC
) {
582 if (cmd
== P80211_IFTEST
) {
585 } else if (cmd
!= P80211_IFREQ
) {
590 /* Allocate a buf of size req->len */
591 msgbuf
= kmalloc(req
->len
, GFP_KERNEL
);
593 if (copy_from_user(msgbuf
, (void __user
*)req
->data
, req
->len
))
596 result
= p80211req_dorequest(wlandev
, msgbuf
);
600 ((void __user
*)req
->data
, msgbuf
, req
->len
)) {
609 /* If allocate,copyfrom or copyto fails, return errno */
613 /*----------------------------------------------------------------
614 * p80211knetdev_set_mac_address
616 * Handles the ioctl for changing the MACAddress of a netdevice
618 * references: linux/netdevice.h and drivers/net/net_init.c
620 * NOTE: [MSM] We only prevent address changes when the netdev is
621 * up. We don't control anything based on dot11 state. If the
622 * address is changed on a STA that's currently associated, you
623 * will probably lose the ability to send and receive data frames.
624 * Just be aware. Therefore, this should usually only be done
625 * prior to scan/join/auth/assoc.
628 * dev netdevice struct
629 * addr the new MACAddress (a struct)
632 * zero on success, a negative errno on failure. Possible values:
633 * -EBUSY device is bussy (cmd not possible)
634 * -and errors returned by: p80211req_dorequest(..)
636 * by: Collin R. Mulliner <collin@mulliner.org>
637 ----------------------------------------------------------------*/
638 static int p80211knetdev_set_mac_address(netdevice_t
*dev
, void *addr
)
640 struct sockaddr
*new_addr
= addr
;
641 struct p80211msg_dot11req_mibset dot11req
;
642 p80211item_unk392_t
*mibattr
;
643 p80211item_pstr6_t
*macaddr
;
644 p80211item_uint32_t
*resultcode
;
647 /* If we're running, we don't allow MAC address changes */
648 if (netif_running(dev
))
651 /* Set up some convenience pointers. */
652 mibattr
= &dot11req
.mibattribute
;
653 macaddr
= (p80211item_pstr6_t
*) &mibattr
->data
;
654 resultcode
= &dot11req
.resultcode
;
656 /* Set up a dot11req_mibset */
657 memset(&dot11req
, 0, sizeof(struct p80211msg_dot11req_mibset
));
658 dot11req
.msgcode
= DIDmsg_dot11req_mibset
;
659 dot11req
.msglen
= sizeof(struct p80211msg_dot11req_mibset
);
660 memcpy(dot11req
.devname
,
661 ((wlandevice_t
*) dev
->ml_priv
)->name
, WLAN_DEVNAMELEN_MAX
- 1);
663 /* Set up the mibattribute argument */
664 mibattr
->did
= DIDmsg_dot11req_mibset_mibattribute
;
665 mibattr
->status
= P80211ENUM_msgitem_status_data_ok
;
666 mibattr
->len
= sizeof(mibattr
->data
);
668 macaddr
->did
= DIDmib_dot11mac_dot11OperationTable_dot11MACAddress
;
669 macaddr
->status
= P80211ENUM_msgitem_status_data_ok
;
670 macaddr
->len
= sizeof(macaddr
->data
);
671 macaddr
->data
.len
= ETH_ALEN
;
672 memcpy(&macaddr
->data
.data
, new_addr
->sa_data
, ETH_ALEN
);
674 /* Set up the resultcode argument */
675 resultcode
->did
= DIDmsg_dot11req_mibset_resultcode
;
676 resultcode
->status
= P80211ENUM_msgitem_status_no_value
;
677 resultcode
->len
= sizeof(resultcode
->data
);
678 resultcode
->data
= 0;
680 /* now fire the request */
681 result
= p80211req_dorequest(dev
->ml_priv
, (u8
*) &dot11req
);
683 /* If the request wasn't successful, report an error and don't
684 * change the netdev address
686 if (result
!= 0 || resultcode
->data
!= P80211ENUM_resultcode_success
) {
687 netdev_err(dev
, "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
688 result
= -EADDRNOTAVAIL
;
690 /* everything's ok, change the addr in netdev */
691 memcpy(dev
->dev_addr
, new_addr
->sa_data
, dev
->addr_len
);
697 static int wlan_change_mtu(netdevice_t
*dev
, int new_mtu
)
699 /* 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
700 and another 8 for wep. */
701 if ((new_mtu
< 68) || (new_mtu
> (2312 - 20 - 8)))
709 static const struct net_device_ops p80211_netdev_ops
= {
710 .ndo_init
= p80211knetdev_init
,
711 .ndo_open
= p80211knetdev_open
,
712 .ndo_stop
= p80211knetdev_stop
,
713 .ndo_get_stats
= p80211knetdev_get_stats
,
714 .ndo_start_xmit
= p80211knetdev_hard_start_xmit
,
715 .ndo_set_rx_mode
= p80211knetdev_set_multicast_list
,
716 .ndo_do_ioctl
= p80211knetdev_do_ioctl
,
717 .ndo_set_mac_address
= p80211knetdev_set_mac_address
,
718 .ndo_tx_timeout
= p80211knetdev_tx_timeout
,
719 .ndo_change_mtu
= wlan_change_mtu
,
720 .ndo_validate_addr
= eth_validate_addr
,
723 /*----------------------------------------------------------------
726 * Roughly matches the functionality of ether_setup. Here
727 * we set up any members of the wlandevice structure that are common
728 * to all devices. Additionally, we allocate a linux 'struct device'
729 * and perform the same setup as ether_setup.
731 * Note: It's important that the caller have setup the wlandev->name
732 * ptr prior to calling this function.
735 * wlandev ptr to the wlandev structure for the
737 * physdev ptr to usb device
739 * zero on success, non-zero otherwise.
741 * Should be process thread. We'll assume it might be
742 * interrupt though. When we add support for statically
743 * compiled drivers, this function will be called in the
744 * context of the kernel startup code.
745 ----------------------------------------------------------------*/
746 int wlan_setup(wlandevice_t
*wlandev
, struct device
*physdev
)
751 struct wireless_dev
*wdev
;
753 /* Set up the wlandev */
754 wlandev
->state
= WLAN_DEVICE_CLOSED
;
755 wlandev
->ethconv
= WLAN_ETHCONV_8021h
;
756 wlandev
->macmode
= WLAN_MACMODE_NONE
;
758 /* Set up the rx queue */
759 skb_queue_head_init(&wlandev
->nsd_rxq
);
760 tasklet_init(&wlandev
->rx_bh
,
761 p80211netdev_rx_bh
, (unsigned long)wlandev
);
763 /* Allocate and initialize the wiphy struct */
764 wiphy
= wlan_create_wiphy(physdev
, wlandev
);
766 dev_err(physdev
, "Failed to alloc wiphy.\n");
770 /* Allocate and initialize the struct device */
771 netdev
= alloc_netdev(sizeof(struct wireless_dev
), "wlan%d",
773 if (netdev
== NULL
) {
774 dev_err(physdev
, "Failed to alloc netdev.\n");
775 wlan_free_wiphy(wiphy
);
778 wlandev
->netdev
= netdev
;
779 netdev
->ml_priv
= wlandev
;
780 netdev
->netdev_ops
= &p80211_netdev_ops
;
781 wdev
= netdev_priv(netdev
);
783 wdev
->iftype
= NL80211_IFTYPE_STATION
;
784 netdev
->ieee80211_ptr
= wdev
;
786 netif_stop_queue(netdev
);
787 netif_carrier_off(netdev
);
793 /*----------------------------------------------------------------
796 * This function is paired with the wlan_setup routine. It should
797 * be called after unregister_wlandev. Basically, all it does is
798 * free the 'struct device' that's associated with the wlandev.
799 * We do it here because the 'struct device' isn't allocated
800 * explicitly in the driver code, it's done in wlan_setup. To
801 * do the free in the driver might seem like 'magic'.
804 * wlandev ptr to the wlandev structure for the
807 * Should be process thread. We'll assume it might be
808 * interrupt though. When we add support for statically
809 * compiled drivers, this function will be called in the
810 * context of the kernel startup code.
811 ----------------------------------------------------------------*/
812 void wlan_unsetup(wlandevice_t
*wlandev
)
814 struct wireless_dev
*wdev
;
816 tasklet_kill(&wlandev
->rx_bh
);
818 if (wlandev
->netdev
) {
819 wdev
= netdev_priv(wlandev
->netdev
);
821 wlan_free_wiphy(wdev
->wiphy
);
822 free_netdev(wlandev
->netdev
);
823 wlandev
->netdev
= NULL
;
827 /*----------------------------------------------------------------
830 * Roughly matches the functionality of register_netdev. This function
831 * is called after the driver has successfully probed and set up the
832 * resources for the device. It's now ready to become a named device
833 * in the Linux system.
835 * First we allocate a name for the device (if not already set), then
836 * we call the Linux function register_netdevice.
839 * wlandev ptr to the wlandev structure for the
842 * zero on success, non-zero otherwise.
844 * Can be either interrupt or not.
845 ----------------------------------------------------------------*/
846 int register_wlandev(wlandevice_t
*wlandev
)
848 return register_netdev(wlandev
->netdev
);
851 /*----------------------------------------------------------------
854 * Roughly matches the functionality of unregister_netdev. This
855 * function is called to remove a named device from the system.
857 * First we tell linux that the device should no longer exist.
858 * Then we remove it from the list of known wlan devices.
861 * wlandev ptr to the wlandev structure for the
864 * zero on success, non-zero otherwise.
866 * Can be either interrupt or not.
867 ----------------------------------------------------------------*/
868 int unregister_wlandev(wlandevice_t
*wlandev
)
872 unregister_netdev(wlandev
->netdev
);
874 /* Now to clean out the rx queue */
875 while ((skb
= skb_dequeue(&wlandev
->nsd_rxq
)))
881 /*----------------------------------------------------------------
882 * p80211netdev_hwremoved
884 * Hardware removed notification. This function should be called
885 * immediately after an MSD has detected that the underlying hardware
886 * has been yanked out from under us. The primary things we need
889 * - Prevent any further traffic from the knetdev i/f
890 * - Prevent any further requests from mgmt i/f
891 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
893 * - Call the MSD hwremoved function.
895 * The remainder of the cleanup will be handled by unregister().
896 * Our primary goal here is to prevent as much tickling of the MSD
897 * as possible since the MSD is already in a 'wounded' state.
899 * TODO: As new features are added, this function should be
903 * wlandev WLAN network device structure
910 ----------------------------------------------------------------*/
911 void p80211netdev_hwremoved(wlandevice_t
*wlandev
)
913 wlandev
->hwremoved
= 1;
914 if (wlandev
->state
== WLAN_DEVICE_OPEN
)
915 netif_stop_queue(wlandev
->netdev
);
917 netif_device_detach(wlandev
->netdev
);
920 /*----------------------------------------------------------------
923 * Classifies the frame, increments the appropriate counter, and
924 * returns 0|1|2 indicating whether the driver should handle, ignore, or
928 * wlandev wlan device structure
929 * fc frame control field
932 * zero if the frame should be handled by the driver,
933 * one if the frame should be ignored
934 * anything else means we drop it.
940 ----------------------------------------------------------------*/
941 static int p80211_rx_typedrop(wlandevice_t
*wlandev
, u16 fc
)
946 /* Classify frame, increment counter */
947 ftype
= WLAN_GET_FC_FTYPE(fc
);
948 fstype
= WLAN_GET_FC_FSTYPE(fc
);
950 netdev_dbg(wlandev
->netdev
, "rx_typedrop : ftype=%d fstype=%d.\n",
954 case WLAN_FTYPE_MGMT
:
955 if ((wlandev
->netdev
->flags
& IFF_PROMISC
) ||
956 (wlandev
->netdev
->flags
& IFF_ALLMULTI
)) {
960 netdev_dbg(wlandev
->netdev
, "rx'd mgmt:\n");
963 case WLAN_FSTYPE_ASSOCREQ
:
964 /* printk("assocreq"); */
965 wlandev
->rx
.assocreq
++;
967 case WLAN_FSTYPE_ASSOCRESP
:
968 /* printk("assocresp"); */
969 wlandev
->rx
.assocresp
++;
971 case WLAN_FSTYPE_REASSOCREQ
:
972 /* printk("reassocreq"); */
973 wlandev
->rx
.reassocreq
++;
975 case WLAN_FSTYPE_REASSOCRESP
:
976 /* printk("reassocresp"); */
977 wlandev
->rx
.reassocresp
++;
979 case WLAN_FSTYPE_PROBEREQ
:
980 /* printk("probereq"); */
981 wlandev
->rx
.probereq
++;
983 case WLAN_FSTYPE_PROBERESP
:
984 /* printk("proberesp"); */
985 wlandev
->rx
.proberesp
++;
987 case WLAN_FSTYPE_BEACON
:
988 /* printk("beacon"); */
989 wlandev
->rx
.beacon
++;
991 case WLAN_FSTYPE_ATIM
:
992 /* printk("atim"); */
995 case WLAN_FSTYPE_DISASSOC
:
996 /* printk("disassoc"); */
997 wlandev
->rx
.disassoc
++;
999 case WLAN_FSTYPE_AUTHEN
:
1000 /* printk("authen"); */
1001 wlandev
->rx
.authen
++;
1003 case WLAN_FSTYPE_DEAUTHEN
:
1004 /* printk("deauthen"); */
1005 wlandev
->rx
.deauthen
++;
1008 /* printk("unknown"); */
1009 wlandev
->rx
.mgmt_unknown
++;
1016 case WLAN_FTYPE_CTL
:
1017 if ((wlandev
->netdev
->flags
& IFF_PROMISC
) ||
1018 (wlandev
->netdev
->flags
& IFF_ALLMULTI
)) {
1022 netdev_dbg(wlandev
->netdev
, "rx'd ctl:\n");
1025 case WLAN_FSTYPE_PSPOLL
:
1026 /* printk("pspoll"); */
1027 wlandev
->rx
.pspoll
++;
1029 case WLAN_FSTYPE_RTS
:
1030 /* printk("rts"); */
1033 case WLAN_FSTYPE_CTS
:
1034 /* printk("cts"); */
1037 case WLAN_FSTYPE_ACK
:
1038 /* printk("ack"); */
1041 case WLAN_FSTYPE_CFEND
:
1042 /* printk("cfend"); */
1043 wlandev
->rx
.cfend
++;
1045 case WLAN_FSTYPE_CFENDCFACK
:
1046 /* printk("cfendcfack"); */
1047 wlandev
->rx
.cfendcfack
++;
1050 /* printk("unknown"); */
1051 wlandev
->rx
.ctl_unknown
++;
1058 case WLAN_FTYPE_DATA
:
1061 case WLAN_FSTYPE_DATAONLY
:
1062 wlandev
->rx
.dataonly
++;
1064 case WLAN_FSTYPE_DATA_CFACK
:
1065 wlandev
->rx
.data_cfack
++;
1067 case WLAN_FSTYPE_DATA_CFPOLL
:
1068 wlandev
->rx
.data_cfpoll
++;
1070 case WLAN_FSTYPE_DATA_CFACK_CFPOLL
:
1071 wlandev
->rx
.data__cfack_cfpoll
++;
1073 case WLAN_FSTYPE_NULL
:
1074 netdev_dbg(wlandev
->netdev
, "rx'd data:null\n");
1077 case WLAN_FSTYPE_CFACK
:
1078 netdev_dbg(wlandev
->netdev
, "rx'd data:cfack\n");
1079 wlandev
->rx
.cfack
++;
1081 case WLAN_FSTYPE_CFPOLL
:
1082 netdev_dbg(wlandev
->netdev
, "rx'd data:cfpoll\n");
1083 wlandev
->rx
.cfpoll
++;
1085 case WLAN_FSTYPE_CFACK_CFPOLL
:
1086 netdev_dbg(wlandev
->netdev
, "rx'd data:cfack_cfpoll\n");
1087 wlandev
->rx
.cfack_cfpoll
++;
1090 /* printk("unknown"); */
1091 wlandev
->rx
.data_unknown
++;
1100 static void p80211knetdev_tx_timeout(netdevice_t
*netdev
)
1102 wlandevice_t
*wlandev
= netdev
->ml_priv
;
1104 if (wlandev
->tx_timeout
) {
1105 wlandev
->tx_timeout(wlandev
);
1107 netdev_warn(netdev
, "Implement tx_timeout for %s\n",
1109 netif_wake_queue(wlandev
->netdev
);