Staging: wlan-ng: Wireless Extension support is mandatory.
[linux-2.6/verdex.git] / drivers / staging / wlan-ng / p80211netdev.c
blob23507c7a54b0fd4bf252d6d18d4d6a90c1610846
1 /* src/p80211/p80211knetdev.c
3 * Linux Kernel net device interface
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
8 * linux-wlan
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
34 * made directly to:
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
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 /*================================================================*/
54 /* System Includes */
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>
78 #ifdef SIOCETHTOOL
79 #include <linux/ethtool.h>
80 #endif
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 /*================================================================*/
104 /* Local Macros */
107 /*================================================================*/
108 /* Local Types */
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
141 * load time.
143 * Arguments:
144 * none
146 * Returns:
147 * nothing
148 ----------------------------------------------------------------*/
149 void p80211netdev_startup(void)
151 DBFENTER;
153 DBFEXIT;
154 return;
157 /*----------------------------------------------------------------
158 * p80211knetdev_shutdown
160 * Shutdown the wlandevice/netdevice part of 802.11 services at
161 * unload time.
163 * Arguments:
164 * none
166 * Returns:
167 * nothing
168 ----------------------------------------------------------------*/
169 void
170 p80211netdev_shutdown(void)
172 DBFENTER;
173 DBFEXIT;
176 /*----------------------------------------------------------------
177 * p80211knetdev_init
179 * Init method for a Linux netdevice. Called in response to
180 * register_netdev.
182 * Arguments:
183 * none
185 * Returns:
186 * nothing
187 ----------------------------------------------------------------*/
188 static int p80211knetdev_init( netdevice_t *netdev)
190 DBFENTER;
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 */
195 DBFEXIT;
196 return 0;
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.
208 * Arguments:
209 * netdev Linux netdevice
211 * Returns:
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;
218 DBFENTER;
220 /* TODO: review the MIB stats for items that correspond to
221 linux stats */
223 DBFEXIT;
224 return &(wlandev->linux_stats);
228 /*----------------------------------------------------------------
229 * p80211knetdev_open
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
234 * MAC below.
236 * Arguments:
237 * netdev Linux network device structure
239 * Returns:
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;
247 DBFENTER;
249 /* Check to make sure the MSD is running */
250 if ( wlandev->msdstate != WLAN_MSD_RUNNING ) {
251 return -ENODEV;
254 /* Tell the MSD to open */
255 if ( wlandev->open != NULL) {
256 result = wlandev->open(wlandev);
257 if ( result == 0 ) {
258 p80211netdev_start_queue(wlandev);
259 wlandev->state = WLAN_DEVICE_OPEN;
261 } else {
262 result = -EAGAIN;
265 DBFEXIT;
266 return result;
270 /*----------------------------------------------------------------
271 * p80211knetdev_stop
273 * Linux netdevice stop (close) method. Following this call,
274 * no frames should go up or down through this interface.
276 * Arguments:
277 * netdev Linux network device structure
279 * Returns:
280 * zero on success, non-zero otherwise
281 ----------------------------------------------------------------*/
282 static int p80211knetdev_stop( netdevice_t *netdev )
284 int result = 0;
285 wlandevice_t *wlandev = netdev->ml_priv;
287 DBFENTER;
289 if ( wlandev->close != NULL ) {
290 result = wlandev->close(wlandev);
293 p80211netdev_stop_queue(wlandev);
294 wlandev->state = WLAN_DEVICE_CLOSED;
296 DBFEXIT;
297 return result;
300 /*----------------------------------------------------------------
301 * p80211netdev_rx
303 * Frame receive function called by the mac specific driver.
305 * Arguments:
306 * wlandev WLAN network device structure
307 * skb skbuff containing a full 802.11 frame.
308 * Returns:
309 * nothing
310 * Side effects:
312 ----------------------------------------------------------------*/
313 void
314 p80211netdev_rx(wlandevice_t *wlandev, struct sk_buff *skb )
316 DBFENTER;
318 /* Enqueue for post-irq processing */
319 skb_queue_tail(&wlandev->nsd_rxq, skb);
321 tasklet_schedule(&wlandev->rx_bh);
323 DBFEXIT;
324 return;
327 /*----------------------------------------------------------------
328 * p80211netdev_rx_bh
330 * Deferred processing of all received frames.
332 * Arguments:
333 * wlandev WLAN network device structure
334 * skb skbuff containing a full 802.11 frame.
335 * Returns:
336 * nothing
337 * Side effects:
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;
346 u16 fc;
348 DBFENTER;
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 */
359 skb->dev = dev;
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;
368 netif_rx_ni(skb);
369 continue;
370 } else {
371 hdr = (p80211_hdr_a3_t *)skb->data;
372 fc = ieee2host16(hdr->fc);
373 if (p80211_rx_typedrop(wlandev, fc)) {
374 dev_kfree_skb(skb);
375 continue;
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)) {
384 dev_kfree_skb(skb);
385 continue;
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;
394 netif_rx_ni(skb);
395 continue;
397 WLAN_LOG_DEBUG(1, "p80211_to_ether failed.\n");
400 dev_kfree_skb(skb);
403 DBFEXIT;
407 /*----------------------------------------------------------------
408 * p80211knetdev_hard_start_xmit
410 * Linux netdevice method for transmitting a frame.
412 * Arguments:
413 * skb Linux sk_buff containing the frame.
414 * netdev Linux netdevice.
416 * Side effects:
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.
423 * Returns:
424 * zero on success, non-zero on failure.
425 ----------------------------------------------------------------*/
426 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev)
428 int result = 0;
429 int txresult = -1;
430 wlandevice_t *wlandev = netdev->ml_priv;
431 p80211_hdr_t p80211_hdr;
432 p80211_metawep_t p80211_wep;
434 DBFENTER;
436 if (skb == NULL) {
437 return 0;
440 if (wlandev->state != WLAN_DEVICE_OPEN) {
441 result = 1;
442 goto failed;
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");
450 result = 1;
451 goto failed;
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:
461 break;
462 default:
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);
469 WLAN_LOG_NOTICE(
470 "Tx attempt prior to association, frame dropped.\n");
471 wlandev->linux_stats.tx_dropped++;
472 result = 0;
473 goto failed;
475 break;
478 /* Check for raw transmits */
479 if(skb->protocol == ETH_P_80211_RAW) {
480 if (!capable(CAP_NET_ADMIN)) {
481 result = 1;
482 goto failed;
484 /* move the header over */
485 memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));
486 skb_pull(skb, sizeof(p80211_hdr_t));
487 } else {
488 if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {
489 /* convert failed */
490 WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n",
491 wlandev->ethconv);
492 result = 1;
493 goto failed;
496 if ( wlandev->txframe == NULL ) {
497 result = 1;
498 goto failed;
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);
513 result = 0;
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 */
519 result = 0;
520 } else if ( txresult == 2 ) {
521 /* alloc failure, drop frame */
522 WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");
523 result = 1;
524 } else {
525 /* buffer full or queue busy, drop frame. */
526 WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");
527 result = 1;
530 failed:
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. */
536 if (!result)
537 dev_kfree_skb(skb);
539 DBFEXIT;
540 return result;
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.
550 * Arguments:
551 * none
553 * Returns:
554 * nothing
555 ----------------------------------------------------------------*/
556 static void p80211knetdev_set_multicast_list(netdevice_t *dev)
558 wlandevice_t *wlandev = dev->ml_priv;
560 DBFENTER;
562 /* TODO: real multicast support as well */
564 if (wlandev->set_multicast_list)
565 wlandev->set_multicast_list(wlandev, dev);
567 DBFEXIT;
570 #ifdef SIOCETHTOOL
572 static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
574 u32 ethcmd;
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(&ethcmd, useraddr, sizeof(ethcmd)))
582 return -EFAULT;
584 switch (ethcmd) {
585 case ETHTOOL_GDRVINFO:
586 info.cmd = ethcmd;
587 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
588 wlandev->nsdname);
589 snprintf(info.version, sizeof(info.version), "%s",
590 WLAN_RELEASE);
592 // info.fw_version
593 // info.bus_info
595 if (copy_to_user(useraddr, &info, sizeof(info)))
596 return -EFAULT;
597 return 0;
598 #ifdef ETHTOOL_GLINK
599 case ETHTOOL_GLINK:
600 edata.cmd = ethcmd;
602 if (wlandev->linkstatus &&
603 (wlandev->macmode != WLAN_MACMODE_NONE)) {
604 edata.data = 1;
605 } else {
606 edata.data = 0;
609 if (copy_to_user(useraddr, &edata, sizeof(edata)))
610 return -EFAULT;
611 return 0;
613 #endif
615 return -EOPNOTSUPP;
618 #endif
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.
627 * Arguments:
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
631 * w/o cast.
633 * Returns:
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.
643 * Call Context:
644 * Process thread (ioctl caller). TODO: SMP support may require
645 * locks.
646 ----------------------------------------------------------------*/
647 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd)
649 int result = 0;
650 p80211ioctl_req_t *req = (p80211ioctl_req_t*)ifr;
651 wlandevice_t *wlandev = dev->ml_priv;
652 u8 *msgbuf;
653 DBFENTER;
655 WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
657 #ifdef SIOCETHTOOL
658 if (cmd == SIOCETHTOOL) {
659 result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);
660 goto bail;
662 #endif
664 /* Test the magic, assume ifr is good if it's there */
665 if ( req->magic != P80211_IOCTL_MAGIC ) {
666 result = -ENOSYS;
667 goto bail;
670 if ( cmd == P80211_IFTEST ) {
671 result = 0;
672 goto bail;
673 } else if ( cmd != P80211_IFREQ ) {
674 result = -ENOSYS;
675 goto bail;
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) ) {
681 result = -EFAULT;
682 } else {
683 result = p80211req_dorequest( wlandev, msgbuf);
686 if ( result == 0 ) {
687 if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {
688 result = -EFAULT;
691 kfree(msgbuf);
692 } else {
693 result = -ENOMEM;
695 bail:
696 DBFEXIT;
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.
715 * Arguments:
716 * dev netdevice struct
717 * addr the new MACAddress (a struct)
719 * Returns:
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;
733 int result = 0;
735 DBFENTER;
736 /* If we're running, we don't allow MAC address changes */
737 if (netif_running(dev)) {
738 return -EBUSY;
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) {
778 WLAN_LOG_ERROR(
779 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
780 result = -EADDRNOTAVAIL;
781 } else {
782 /* everything's ok, change the addr in netdev */
783 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
786 DBFEXIT;
787 return result;
790 static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
792 DBFENTER;
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)))
796 return -EINVAL;
798 dev->mtu = new_mtu;
800 DBFEXIT;
802 return 0;
807 /*----------------------------------------------------------------
808 * wlan_setup
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.
818 * Arguments:
819 * wlandev ptr to the wlandev structure for the
820 * interface.
821 * Returns:
822 * zero on success, non-zero otherwise.
823 * Call Context:
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)
831 int result = 0;
832 netdevice_t *dev;
834 DBFENTER;
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,
844 p80211netdev_rx_bh,
845 (unsigned long)wlandev);
847 /* Allocate and initialize the struct device */
848 dev = kmalloc(sizeof(netdevice_t), GFP_ATOMIC);
849 if ( dev == NULL ) {
850 WLAN_LOG_ERROR("Failed to alloc netdev.\n");
851 result = 1;
852 } else {
853 memset( dev, 0, sizeof(netdevice_t));
854 ether_setup(dev);
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;
861 #endif
862 #ifdef HAVE_MULTICAST
863 dev->set_multicast_list = p80211knetdev_set_multicast_list;
864 #endif
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;
871 #endif
872 dev->wireless_handlers = &p80211wext_handler_def;
874 netif_stop_queue(dev);
875 #ifdef HAVE_CHANGE_MTU
876 dev->change_mtu = wlan_change_mtu;
877 #endif
878 #ifdef HAVE_SET_MAC_ADDR
879 dev->set_mac_address = p80211knetdev_set_mac_address;
880 #endif
881 #ifdef HAVE_TX_TIMEOUT
882 dev->tx_timeout = &p80211knetdev_tx_timeout;
883 dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000;
884 #endif
885 netif_carrier_off(dev);
888 DBFEXIT;
889 return result;
892 /*----------------------------------------------------------------
893 * wlan_unsetup
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'.
902 * Arguments:
903 * wlandev ptr to the wlandev structure for the
904 * interface.
905 * Returns:
906 * zero on success, non-zero otherwise.
907 * Call Context:
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)
915 int result = 0;
917 DBFENTER;
919 tasklet_kill(&wlandev->rx_bh);
921 if (wlandev->netdev == NULL ) {
922 WLAN_LOG_ERROR("called without wlandev->netdev set.\n");
923 result = 1;
924 } else {
925 free_netdev(wlandev->netdev);
926 wlandev->netdev = NULL;
929 DBFEXIT;
930 return 0;
935 /*----------------------------------------------------------------
936 * register_wlandev
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.
946 * Arguments:
947 * wlandev ptr to the wlandev structure for the
948 * interface.
949 * Returns:
950 * zero on success, non-zero otherwise.
951 * Call Context:
952 * Can be either interrupt or not.
953 ----------------------------------------------------------------*/
954 int register_wlandev(wlandevice_t *wlandev)
956 int i = 0;
957 netdevice_t *dev = wlandev->netdev;
959 DBFENTER;
961 i = dev_alloc_name(wlandev->netdev, "wlan%d");
962 if (i >= 0) {
963 i = register_netdev(wlandev->netdev);
965 if (i != 0) {
966 return -EIO;
969 strcpy(wlandev->name, dev->name);
971 DBFEXIT;
972 return 0;
976 /*----------------------------------------------------------------
977 * unregister_wlandev
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.
985 * Arguments:
986 * wlandev ptr to the wlandev structure for the
987 * interface.
988 * Returns:
989 * zero on success, non-zero otherwise.
990 * Call Context:
991 * Can be either interrupt or not.
992 ----------------------------------------------------------------*/
993 int unregister_wlandev(wlandevice_t *wlandev)
995 struct sk_buff *skb;
997 DBFENTER;
999 unregister_netdev(wlandev->netdev);
1001 /* Now to clean out the rx queue */
1002 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
1003 dev_kfree_skb(skb);
1006 DBFEXIT;
1007 return 0;
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
1017 * to do are:
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,
1022 * shut them down.
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
1030 * updated.
1032 * Arguments:
1033 * wlandev WLAN network device structure
1034 * Returns:
1035 * nothing
1036 * Side effects:
1038 * Call context:
1039 * Usually interrupt.
1040 ----------------------------------------------------------------*/
1041 void p80211netdev_hwremoved(wlandevice_t *wlandev)
1043 DBFENTER;
1044 wlandev->hwremoved = 1;
1045 if ( wlandev->state == WLAN_DEVICE_OPEN) {
1046 p80211netdev_stop_queue(wlandev);
1049 netif_device_detach(wlandev->netdev);
1051 DBFEXIT;
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
1060 * drop the frame
1062 * Arguments:
1063 * wlandev wlan device structure
1064 * fc frame control field
1066 * Returns:
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.
1071 * Side effects:
1073 * Call context:
1074 * interrupt
1075 ----------------------------------------------------------------*/
1076 static int p80211_rx_typedrop( wlandevice_t *wlandev, u16 fc)
1078 u16 ftype;
1079 u16 fstype;
1080 int drop = 0;
1081 /* Classify frame, increment counter */
1082 ftype = WLAN_GET_FC_FTYPE(fc);
1083 fstype = WLAN_GET_FC_FSTYPE(fc);
1084 #if 0
1085 WLAN_LOG_DEBUG(4,
1086 "rx_typedrop : ftype=%d fstype=%d.\n", ftype, fstype);
1087 #endif
1088 switch ( ftype ) {
1089 case WLAN_FTYPE_MGMT:
1090 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1091 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1092 drop = 1;
1093 break;
1095 WLAN_LOG_DEBUG(3, "rx'd mgmt:\n");
1096 wlandev->rx.mgmt++;
1097 switch( fstype ) {
1098 case WLAN_FSTYPE_ASSOCREQ:
1099 /* printk("assocreq"); */
1100 wlandev->rx.assocreq++;
1101 break;
1102 case WLAN_FSTYPE_ASSOCRESP:
1103 /* printk("assocresp"); */
1104 wlandev->rx.assocresp++;
1105 break;
1106 case WLAN_FSTYPE_REASSOCREQ:
1107 /* printk("reassocreq"); */
1108 wlandev->rx.reassocreq++;
1109 break;
1110 case WLAN_FSTYPE_REASSOCRESP:
1111 /* printk("reassocresp"); */
1112 wlandev->rx.reassocresp++;
1113 break;
1114 case WLAN_FSTYPE_PROBEREQ:
1115 /* printk("probereq"); */
1116 wlandev->rx.probereq++;
1117 break;
1118 case WLAN_FSTYPE_PROBERESP:
1119 /* printk("proberesp"); */
1120 wlandev->rx.proberesp++;
1121 break;
1122 case WLAN_FSTYPE_BEACON:
1123 /* printk("beacon"); */
1124 wlandev->rx.beacon++;
1125 break;
1126 case WLAN_FSTYPE_ATIM:
1127 /* printk("atim"); */
1128 wlandev->rx.atim++;
1129 break;
1130 case WLAN_FSTYPE_DISASSOC:
1131 /* printk("disassoc"); */
1132 wlandev->rx.disassoc++;
1133 break;
1134 case WLAN_FSTYPE_AUTHEN:
1135 /* printk("authen"); */
1136 wlandev->rx.authen++;
1137 break;
1138 case WLAN_FSTYPE_DEAUTHEN:
1139 /* printk("deauthen"); */
1140 wlandev->rx.deauthen++;
1141 break;
1142 default:
1143 /* printk("unknown"); */
1144 wlandev->rx.mgmt_unknown++;
1145 break;
1147 /* printk("\n"); */
1148 drop = 2;
1149 break;
1151 case WLAN_FTYPE_CTL:
1152 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1153 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1154 drop = 1;
1155 break;
1157 WLAN_LOG_DEBUG(3, "rx'd ctl:\n");
1158 wlandev->rx.ctl++;
1159 switch( fstype ) {
1160 case WLAN_FSTYPE_PSPOLL:
1161 /* printk("pspoll"); */
1162 wlandev->rx.pspoll++;
1163 break;
1164 case WLAN_FSTYPE_RTS:
1165 /* printk("rts"); */
1166 wlandev->rx.rts++;
1167 break;
1168 case WLAN_FSTYPE_CTS:
1169 /* printk("cts"); */
1170 wlandev->rx.cts++;
1171 break;
1172 case WLAN_FSTYPE_ACK:
1173 /* printk("ack"); */
1174 wlandev->rx.ack++;
1175 break;
1176 case WLAN_FSTYPE_CFEND:
1177 /* printk("cfend"); */
1178 wlandev->rx.cfend++;
1179 break;
1180 case WLAN_FSTYPE_CFENDCFACK:
1181 /* printk("cfendcfack"); */
1182 wlandev->rx.cfendcfack++;
1183 break;
1184 default:
1185 /* printk("unknown"); */
1186 wlandev->rx.ctl_unknown++;
1187 break;
1189 /* printk("\n"); */
1190 drop = 2;
1191 break;
1193 case WLAN_FTYPE_DATA:
1194 wlandev->rx.data++;
1195 switch( fstype ) {
1196 case WLAN_FSTYPE_DATAONLY:
1197 wlandev->rx.dataonly++;
1198 break;
1199 case WLAN_FSTYPE_DATA_CFACK:
1200 wlandev->rx.data_cfack++;
1201 break;
1202 case WLAN_FSTYPE_DATA_CFPOLL:
1203 wlandev->rx.data_cfpoll++;
1204 break;
1205 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1206 wlandev->rx.data__cfack_cfpoll++;
1207 break;
1208 case WLAN_FSTYPE_NULL:
1209 WLAN_LOG_DEBUG(3, "rx'd data:null\n");
1210 wlandev->rx.null++;
1211 break;
1212 case WLAN_FSTYPE_CFACK:
1213 WLAN_LOG_DEBUG(3, "rx'd data:cfack\n");
1214 wlandev->rx.cfack++;
1215 break;
1216 case WLAN_FSTYPE_CFPOLL:
1217 WLAN_LOG_DEBUG(3, "rx'd data:cfpoll\n");
1218 wlandev->rx.cfpoll++;
1219 break;
1220 case WLAN_FSTYPE_CFACK_CFPOLL:
1221 WLAN_LOG_DEBUG(3, "rx'd data:cfack_cfpoll\n");
1222 wlandev->rx.cfack_cfpoll++;
1223 break;
1224 default:
1225 /* printk("unknown"); */
1226 wlandev->rx.data_unknown++;
1227 break;
1230 break;
1232 return drop;
1236 void p80211_suspend(wlandevice_t *wlandev)
1238 DBFENTER;
1240 DBFEXIT;
1243 void p80211_resume(wlandevice_t *wlandev)
1245 DBFENTER;
1247 DBFEXIT;
1250 static void p80211knetdev_tx_timeout( netdevice_t *netdev)
1252 wlandevice_t *wlandev = netdev->ml_priv;
1253 DBFENTER;
1255 if (wlandev->tx_timeout) {
1256 wlandev->tx_timeout(wlandev);
1257 } else {
1258 WLAN_LOG_WARNING("Implement tx_timeout for %s\n",
1259 wlandev->nsdname);
1260 p80211netdev_wake_queue(wlandev);
1263 DBFEXIT;