Staging: add wlan-ng prism2 usb driver
[deliverable/linux.git] / drivers / staging / wlan-ng / p80211netdev.c
1 /* src/p80211/p80211knetdev.c
2 *
3 * Linux Kernel net device interface
4 *
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
7 *
8 * linux-wlan
9 *
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/
14 *
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.
19 *
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.
30 *
31 * --------------------------------------------------------------------
32 *
33 * Inquiries regarding the linux-wlan Open Source project can be
34 * made directly to:
35 *
36 * AbsoluteValue Systems Inc.
37 * info@linux-wlan.com
38 * http://www.linux-wlan.com
39 *
40 * --------------------------------------------------------------------
41 *
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
44 *
45 * --------------------------------------------------------------------
46 *
47 * The functions required for a Linux network device are defined here.
48 *
49 * --------------------------------------------------------------------
50 */
51
52
53 /*================================================================*/
54 /* System Includes */
55
56
57 #include <linux/version.h>
58
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/sched.h>
62 #include <linux/types.h>
63 #include <linux/skbuff.h>
64 #include <linux/slab.h>
65 #include <linux/proc_fs.h>
66 #include <linux/interrupt.h>
67 #include <linux/netdevice.h>
68 #include <linux/kmod.h>
69 #include <linux/if_arp.h>
70 #include <linux/wireless.h>
71 #include <linux/sockios.h>
72 #include <linux/etherdevice.h>
73
74 #include <asm/bitops.h>
75 #include <asm/uaccess.h>
76 #include <asm/byteorder.h>
77
78 #ifdef SIOCETHTOOL
79 #include <linux/ethtool.h>
80 #endif
81
82 #if WIRELESS_EXT > 12
83 #include <net/iw_handler.h>
84 #endif
85 #include <net/net_namespace.h>
86
87 /*================================================================*/
88 /* Project Includes */
89
90 #include "version.h"
91 #include "wlan_compat.h"
92 #include "p80211types.h"
93 #include "p80211hdr.h"
94 #include "p80211conv.h"
95 #include "p80211mgmt.h"
96 #include "p80211msg.h"
97 #include "p80211netdev.h"
98 #include "p80211ioctl.h"
99 #include "p80211req.h"
100 #include "p80211metastruct.h"
101 #include "p80211metadef.h"
102
103 /*================================================================*/
104 /* Local Constants */
105
106 /*================================================================*/
107 /* Local Macros */
108
109
110 /*================================================================*/
111 /* Local Types */
112
113 /*================================================================*/
114 /* Local Static Definitions */
115
116 #define __NO_VERSION__ /* prevent the static definition */
117
118 #ifdef CONFIG_PROC_FS
119 static struct proc_dir_entry *proc_p80211;
120 #endif
121
122 /*================================================================*/
123 /* Local Function Declarations */
124
125 /* Support functions */
126 static void p80211netdev_rx_bh(unsigned long arg);
127
128 /* netdevice method functions */
129 static int p80211knetdev_init( netdevice_t *netdev);
130 static struct net_device_stats* p80211knetdev_get_stats(netdevice_t *netdev);
131 static int p80211knetdev_open( netdevice_t *netdev);
132 static int p80211knetdev_stop( netdevice_t *netdev );
133 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev);
134 static void p80211knetdev_set_multicast_list(netdevice_t *dev);
135 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd);
136 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr);
137 static void p80211knetdev_tx_timeout(netdevice_t *netdev);
138 static int p80211_rx_typedrop( wlandevice_t *wlandev, UINT16 fc);
139
140 #ifdef CONFIG_PROC_FS
141 static int
142 p80211netdev_proc_read(
143 char *page,
144 char **start,
145 off_t offset,
146 int count,
147 int *eof,
148 void *data);
149 #endif
150
151 /*================================================================*/
152 /* Function Definitions */
153
154 /*----------------------------------------------------------------
155 * p80211knetdev_startup
156 *
157 * Initialize the wlandevice/netdevice part of 802.11 services at
158 * load time.
159 *
160 * Arguments:
161 * none
162 *
163 * Returns:
164 * nothing
165 ----------------------------------------------------------------*/
166 void p80211netdev_startup(void)
167 {
168 DBFENTER;
169
170 #ifdef CONFIG_PROC_FS
171 if (init_net.proc_net != NULL) {
172 proc_p80211 = create_proc_entry(
173 "p80211",
174 (S_IFDIR|S_IRUGO|S_IXUGO),
175 init_net.proc_net);
176 }
177 #endif
178 DBFEXIT;
179 return;
180 }
181
182 /*----------------------------------------------------------------
183 * p80211knetdev_shutdown
184 *
185 * Shutdown the wlandevice/netdevice part of 802.11 services at
186 * unload time.
187 *
188 * Arguments:
189 * none
190 *
191 * Returns:
192 * nothing
193 ----------------------------------------------------------------*/
194 void
195 p80211netdev_shutdown(void)
196 {
197 DBFENTER;
198 #ifdef CONFIG_PROC_FS
199 if (proc_p80211 != NULL) {
200 remove_proc_entry("p80211", init_net.proc_net);
201 }
202 #endif
203 DBFEXIT;
204 }
205
206 /*----------------------------------------------------------------
207 * p80211knetdev_init
208 *
209 * Init method for a Linux netdevice. Called in response to
210 * register_netdev.
211 *
212 * Arguments:
213 * none
214 *
215 * Returns:
216 * nothing
217 ----------------------------------------------------------------*/
218 static int p80211knetdev_init( netdevice_t *netdev)
219 {
220 DBFENTER;
221 /* Called in response to register_netdev */
222 /* This is usually the probe function, but the probe has */
223 /* already been done by the MSD and the create_kdev */
224 /* function. All we do here is return success */
225 DBFEXIT;
226 return 0;
227 }
228
229
230 /*----------------------------------------------------------------
231 * p80211knetdev_get_stats
232 *
233 * Statistics retrieval for linux netdevices. Here we're reporting
234 * the Linux i/f level statistics. Hence, for the primary numbers,
235 * we don't want to report the numbers from the MIB. Eventually,
236 * it might be useful to collect some of the error counters though.
237 *
238 * Arguments:
239 * netdev Linux netdevice
240 *
241 * Returns:
242 * the address of the statistics structure
243 ----------------------------------------------------------------*/
244 static struct net_device_stats*
245 p80211knetdev_get_stats(netdevice_t *netdev)
246 {
247 wlandevice_t *wlandev = (wlandevice_t*)netdev->priv;
248 DBFENTER;
249
250 /* TODO: review the MIB stats for items that correspond to
251 linux stats */
252
253 DBFEXIT;
254 return &(wlandev->linux_stats);
255 }
256
257
258 /*----------------------------------------------------------------
259 * p80211knetdev_open
260 *
261 * Linux netdevice open method. Following a successful call here,
262 * the device is supposed to be ready for tx and rx. In our
263 * situation that may not be entirely true due to the state of the
264 * MAC below.
265 *
266 * Arguments:
267 * netdev Linux network device structure
268 *
269 * Returns:
270 * zero on success, non-zero otherwise
271 ----------------------------------------------------------------*/
272 static int p80211knetdev_open( netdevice_t *netdev )
273 {
274 int result = 0; /* success */
275 wlandevice_t *wlandev = (wlandevice_t*)(netdev->priv);
276
277 DBFENTER;
278
279 /* Check to make sure the MSD is running */
280 if ( wlandev->msdstate != WLAN_MSD_RUNNING ) {
281 return -ENODEV;
282 }
283
284 /* Tell the MSD to open */
285 if ( wlandev->open != NULL) {
286 result = wlandev->open(wlandev);
287 if ( result == 0 ) {
288 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43) )
289 netdev->interrupt = 0;
290 #endif
291 p80211netdev_start_queue(wlandev);
292 wlandev->state = WLAN_DEVICE_OPEN;
293 }
294 } else {
295 result = -EAGAIN;
296 }
297
298 DBFEXIT;
299 return result;
300 }
301
302
303 /*----------------------------------------------------------------
304 * p80211knetdev_stop
305 *
306 * Linux netdevice stop (close) method. Following this call,
307 * no frames should go up or down through this interface.
308 *
309 * Arguments:
310 * netdev Linux network device structure
311 *
312 * Returns:
313 * zero on success, non-zero otherwise
314 ----------------------------------------------------------------*/
315 static int p80211knetdev_stop( netdevice_t *netdev )
316 {
317 int result = 0;
318 wlandevice_t *wlandev = (wlandevice_t*)(netdev->priv);
319
320 DBFENTER;
321
322 if ( wlandev->close != NULL ) {
323 result = wlandev->close(wlandev);
324 }
325
326 p80211netdev_stop_queue(wlandev);
327 wlandev->state = WLAN_DEVICE_CLOSED;
328
329 DBFEXIT;
330 return result;
331 }
332
333 /*----------------------------------------------------------------
334 * p80211netdev_rx
335 *
336 * Frame receive function called by the mac specific driver.
337 *
338 * Arguments:
339 * wlandev WLAN network device structure
340 * skb skbuff containing a full 802.11 frame.
341 * Returns:
342 * nothing
343 * Side effects:
344 *
345 ----------------------------------------------------------------*/
346 void
347 p80211netdev_rx(wlandevice_t *wlandev, struct sk_buff *skb )
348 {
349 DBFENTER;
350
351 /* Enqueue for post-irq processing */
352 skb_queue_tail(&wlandev->nsd_rxq, skb);
353
354 tasklet_schedule(&wlandev->rx_bh);
355
356 DBFEXIT;
357 return;
358 }
359
360 /*----------------------------------------------------------------
361 * p80211netdev_rx_bh
362 *
363 * Deferred processing of all received frames.
364 *
365 * Arguments:
366 * wlandev WLAN network device structure
367 * skb skbuff containing a full 802.11 frame.
368 * Returns:
369 * nothing
370 * Side effects:
371 *
372 ----------------------------------------------------------------*/
373 static void p80211netdev_rx_bh(unsigned long arg)
374 {
375 wlandevice_t *wlandev = (wlandevice_t *) arg;
376 struct sk_buff *skb = NULL;
377 netdevice_t *dev = wlandev->netdev;
378 p80211_hdr_a3_t *hdr;
379 UINT16 fc;
380
381 DBFENTER;
382
383 /* Let's empty our our queue */
384 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
385 if (wlandev->state == WLAN_DEVICE_OPEN) {
386
387 if (dev->type != ARPHRD_ETHER) {
388 /* RAW frame; we shouldn't convert it */
389 // XXX Append the Prism Header here instead.
390
391 /* set up various data fields */
392 skb->dev = dev;
393 skb_reset_mac_header(skb);
394 skb->ip_summed = CHECKSUM_NONE;
395 skb->pkt_type = PACKET_OTHERHOST;
396 skb->protocol = htons(ETH_P_80211_RAW);
397 dev->last_rx = jiffies;
398
399 wlandev->linux_stats.rx_packets++;
400 wlandev->linux_stats.rx_bytes += skb->len;
401 netif_rx_ni(skb);
402 continue;
403 } else {
404 hdr = (p80211_hdr_a3_t *)skb->data;
405 fc = ieee2host16(hdr->fc);
406 if (p80211_rx_typedrop(wlandev, fc)) {
407 dev_kfree_skb(skb);
408 continue;
409 }
410
411 /* perform mcast filtering */
412 if (wlandev->netdev->flags & IFF_ALLMULTI) {
413 /* allow my local address through */
414 if (memcmp(hdr->a1, wlandev->netdev->dev_addr, WLAN_ADDR_LEN) != 0) {
415 /* but reject anything else that isn't multicast */
416 if (!(hdr->a1[0] & 0x01)) {
417 dev_kfree_skb(skb);
418 continue;
419 }
420 }
421 }
422
423 if ( skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0 ) {
424 skb->dev->last_rx = jiffies;
425 wlandev->linux_stats.rx_packets++;
426 wlandev->linux_stats.rx_bytes += skb->len;
427 netif_rx_ni(skb);
428 continue;
429 }
430 WLAN_LOG_DEBUG(1, "p80211_to_ether failed.\n");
431 }
432 }
433 dev_kfree_skb(skb);
434 }
435
436 DBFEXIT;
437 }
438
439
440 /*----------------------------------------------------------------
441 * p80211knetdev_hard_start_xmit
442 *
443 * Linux netdevice method for transmitting a frame.
444 *
445 * Arguments:
446 * skb Linux sk_buff containing the frame.
447 * netdev Linux netdevice.
448 *
449 * Side effects:
450 * If the lower layers report that buffers are full. netdev->tbusy
451 * will be set to prevent higher layers from sending more traffic.
452 *
453 * Note: If this function returns non-zero, higher layers retain
454 * ownership of the skb.
455 *
456 * Returns:
457 * zero on success, non-zero on failure.
458 ----------------------------------------------------------------*/
459 static int p80211knetdev_hard_start_xmit( struct sk_buff *skb, netdevice_t *netdev)
460 {
461 int result = 0;
462 int txresult = -1;
463 wlandevice_t *wlandev = (wlandevice_t*)netdev->priv;
464 p80211_hdr_t p80211_hdr;
465 p80211_metawep_t p80211_wep;
466
467 DBFENTER;
468
469 if (skb == NULL) {
470 return 0;
471 }
472
473 if (wlandev->state != WLAN_DEVICE_OPEN) {
474 result = 1;
475 goto failed;
476 }
477
478 memset(&p80211_hdr, 0, sizeof(p80211_hdr_t));
479 memset(&p80211_wep, 0, sizeof(p80211_metawep_t));
480
481 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38) )
482 if ( test_and_set_bit(0, (void*)&(netdev->tbusy)) != 0 ) {
483 /* We've been called w/ tbusy set, has the tx */
484 /* path stalled? */
485 WLAN_LOG_DEBUG(1, "called when tbusy set\n");
486 result = 1;
487 goto failed;
488 }
489 #else
490 if ( netif_queue_stopped(netdev) ) {
491 WLAN_LOG_DEBUG(1, "called when queue stopped.\n");
492 result = 1;
493 goto failed;
494 }
495
496 netif_stop_queue(netdev);
497
498 /* No timeout handling here, 2.3.38+ kernels call the
499 * timeout function directly.
500 * TODO: Add timeout handling.
501 */
502 #endif
503
504 /* Check to see that a valid mode is set */
505 switch( wlandev->macmode ) {
506 case WLAN_MACMODE_IBSS_STA:
507 case WLAN_MACMODE_ESS_STA:
508 case WLAN_MACMODE_ESS_AP:
509 break;
510 default:
511 /* Mode isn't set yet, just drop the frame
512 * and return success .
513 * TODO: we need a saner way to handle this
514 */
515 if(skb->protocol != ETH_P_80211_RAW) {
516 p80211netdev_start_queue(wlandev);
517 WLAN_LOG_NOTICE(
518 "Tx attempt prior to association, frame dropped.\n");
519 wlandev->linux_stats.tx_dropped++;
520 result = 0;
521 goto failed;
522 }
523 break;
524 }
525
526 /* Check for raw transmits */
527 if(skb->protocol == ETH_P_80211_RAW) {
528 if (!capable(CAP_NET_ADMIN)) {
529 result = 1;
530 goto failed;
531 }
532 /* move the header over */
533 memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr_t));
534 skb_pull(skb, sizeof(p80211_hdr_t));
535 } else {
536 if ( skb_ether_to_p80211(wlandev, wlandev->ethconv, skb, &p80211_hdr, &p80211_wep) != 0 ) {
537 /* convert failed */
538 WLAN_LOG_DEBUG(1, "ether_to_80211(%d) failed.\n",
539 wlandev->ethconv);
540 result = 1;
541 goto failed;
542 }
543 }
544 if ( wlandev->txframe == NULL ) {
545 result = 1;
546 goto failed;
547 }
548
549 netdev->trans_start = jiffies;
550
551 wlandev->linux_stats.tx_packets++;
552 /* count only the packet payload */
553 wlandev->linux_stats.tx_bytes += skb->len;
554
555 txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep);
556
557 if ( txresult == 0) {
558 /* success and more buf */
559 /* avail, re: hw_txdata */
560 p80211netdev_wake_queue(wlandev);
561 result = 0;
562 } else if ( txresult == 1 ) {
563 /* success, no more avail */
564 WLAN_LOG_DEBUG(3, "txframe success, no more bufs\n");
565 /* netdev->tbusy = 1; don't set here, irqhdlr */
566 /* may have already cleared it */
567 result = 0;
568 } else if ( txresult == 2 ) {
569 /* alloc failure, drop frame */
570 WLAN_LOG_DEBUG(3, "txframe returned alloc_fail\n");
571 result = 1;
572 } else {
573 /* buffer full or queue busy, drop frame. */
574 WLAN_LOG_DEBUG(3, "txframe returned full or busy\n");
575 result = 1;
576 }
577
578 failed:
579 /* Free up the WEP buffer if it's not the same as the skb */
580 if ((p80211_wep.data) && (p80211_wep.data != skb->data))
581 kfree(p80211_wep.data);
582
583 /* we always free the skb here, never in a lower level. */
584 if (!result)
585 dev_kfree_skb(skb);
586
587 DBFEXIT;
588 return result;
589 }
590
591
592 /*----------------------------------------------------------------
593 * p80211knetdev_set_multicast_list
594 *
595 * Called from higher lavers whenever there's a need to set/clear
596 * promiscuous mode or rewrite the multicast list.
597 *
598 * Arguments:
599 * none
600 *
601 * Returns:
602 * nothing
603 ----------------------------------------------------------------*/
604 static void p80211knetdev_set_multicast_list(netdevice_t *dev)
605 {
606 wlandevice_t *wlandev = (wlandevice_t*)dev->priv;
607
608 DBFENTER;
609
610 /* TODO: real multicast support as well */
611
612 if (wlandev->set_multicast_list)
613 wlandev->set_multicast_list(wlandev, dev);
614
615 DBFEXIT;
616 }
617
618 #ifdef SIOCETHTOOL
619
620 static int p80211netdev_ethtool(wlandevice_t *wlandev, void __user *useraddr)
621 {
622 UINT32 ethcmd;
623 struct ethtool_drvinfo info;
624 struct ethtool_value edata;
625
626 memset(&info, 0, sizeof(info));
627 memset(&edata, 0, sizeof(edata));
628
629 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
630 return -EFAULT;
631
632 switch (ethcmd) {
633 case ETHTOOL_GDRVINFO:
634 info.cmd = ethcmd;
635 snprintf(info.driver, sizeof(info.driver), "p80211_%s",
636 wlandev->nsdname);
637 snprintf(info.version, sizeof(info.version), "%s",
638 WLAN_RELEASE);
639
640 // info.fw_version
641 // info.bus_info
642
643 if (copy_to_user(useraddr, &info, sizeof(info)))
644 return -EFAULT;
645 return 0;
646 #ifdef ETHTOOL_GLINK
647 case ETHTOOL_GLINK:
648 edata.cmd = ethcmd;
649
650 if (wlandev->linkstatus &&
651 (wlandev->macmode != WLAN_MACMODE_NONE)) {
652 edata.data = 1;
653 } else {
654 edata.data = 0;
655 }
656
657 if (copy_to_user(useraddr, &edata, sizeof(edata)))
658 return -EFAULT;
659 return 0;
660 }
661 #endif
662
663 return -EOPNOTSUPP;
664 }
665
666 #endif
667
668 /*----------------------------------------------------------------
669 * p80211knetdev_do_ioctl
670 *
671 * Handle an ioctl call on one of our devices. Everything Linux
672 * ioctl specific is done here. Then we pass the contents of the
673 * ifr->data to the request message handler.
674 *
675 * Arguments:
676 * dev Linux kernel netdevice
677 * ifr Our private ioctl request structure, typed for the
678 * generic struct ifreq so we can use ptr to func
679 * w/o cast.
680 *
681 * Returns:
682 * zero on success, a negative errno on failure. Possible values:
683 * -ENETDOWN Device isn't up.
684 * -EBUSY cmd already in progress
685 * -ETIME p80211 cmd timed out (MSD may have its own timers)
686 * -EFAULT memory fault copying msg from user buffer
687 * -ENOMEM unable to allocate kernel msg buffer
688 * -ENOSYS bad magic, it the cmd really for us?
689 * -EINTR sleeping on cmd, awakened by signal, cmd cancelled.
690 *
691 * Call Context:
692 * Process thread (ioctl caller). TODO: SMP support may require
693 * locks.
694 ----------------------------------------------------------------*/
695 static int p80211knetdev_do_ioctl(netdevice_t *dev, struct ifreq *ifr, int cmd)
696 {
697 int result = 0;
698 p80211ioctl_req_t *req = (p80211ioctl_req_t*)ifr;
699 wlandevice_t *wlandev = (wlandevice_t*)dev->priv;
700 UINT8 *msgbuf;
701 DBFENTER;
702
703 WLAN_LOG_DEBUG(2, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len);
704
705 #if WIRELESS_EXT < 13
706 /* Is this a wireless extensions ioctl? */
707 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
708 if ((result = p80211wext_support_ioctl(dev, ifr, cmd))
709 != (-EOPNOTSUPP)) {
710 goto bail;
711 }
712 }
713 #endif
714
715 #ifdef SIOCETHTOOL
716 if (cmd == SIOCETHTOOL) {
717 result = p80211netdev_ethtool(wlandev, (void __user *) ifr->ifr_data);
718 goto bail;
719 }
720 #endif
721
722 /* Test the magic, assume ifr is good if it's there */
723 if ( req->magic != P80211_IOCTL_MAGIC ) {
724 result = -ENOSYS;
725 goto bail;
726 }
727
728 if ( cmd == P80211_IFTEST ) {
729 result = 0;
730 goto bail;
731 } else if ( cmd != P80211_IFREQ ) {
732 result = -ENOSYS;
733 goto bail;
734 }
735
736 /* Allocate a buf of size req->len */
737 if ((msgbuf = kmalloc( req->len, GFP_KERNEL))) {
738 if ( copy_from_user( msgbuf, (void __user *) req->data, req->len) ) {
739 result = -EFAULT;
740 } else {
741 result = p80211req_dorequest( wlandev, msgbuf);
742 }
743
744 if ( result == 0 ) {
745 if ( copy_to_user( (void __user *) req->data, msgbuf, req->len)) {
746 result = -EFAULT;
747 }
748 }
749 kfree(msgbuf);
750 } else {
751 result = -ENOMEM;
752 }
753 bail:
754 DBFEXIT;
755
756 return result; /* If allocate,copyfrom or copyto fails, return errno */
757 }
758
759 /*----------------------------------------------------------------
760 * p80211knetdev_set_mac_address
761 *
762 * Handles the ioctl for changing the MACAddress of a netdevice
763 *
764 * references: linux/netdevice.h and drivers/net/net_init.c
765 *
766 * NOTE: [MSM] We only prevent address changes when the netdev is
767 * up. We don't control anything based on dot11 state. If the
768 * address is changed on a STA that's currently associated, you
769 * will probably lose the ability to send and receive data frames.
770 * Just be aware. Therefore, this should usually only be done
771 * prior to scan/join/auth/assoc.
772 *
773 * Arguments:
774 * dev netdevice struct
775 * addr the new MACAddress (a struct)
776 *
777 * Returns:
778 * zero on success, a negative errno on failure. Possible values:
779 * -EBUSY device is bussy (cmd not possible)
780 * -and errors returned by: p80211req_dorequest(..)
781 *
782 * by: Collin R. Mulliner <collin@mulliner.org>
783 ----------------------------------------------------------------*/
784 static int p80211knetdev_set_mac_address(netdevice_t *dev, void *addr)
785 {
786 struct sockaddr *new_addr = addr;
787 p80211msg_dot11req_mibset_t dot11req;
788 p80211item_unk392_t *mibattr;
789 p80211item_pstr6_t *macaddr;
790 p80211item_uint32_t *resultcode;
791 int result = 0;
792
793 DBFENTER;
794 /* If we're running, we don't allow MAC address changes */
795 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38) )
796 if ( dev->start) {
797 return -EBUSY;
798 }
799 #else
800 if (netif_running(dev)) {
801 return -EBUSY;
802 }
803 #endif
804
805 /* Set up some convenience pointers. */
806 mibattr = &dot11req.mibattribute;
807 macaddr = (p80211item_pstr6_t*)&mibattr->data;
808 resultcode = &dot11req.resultcode;
809
810 /* Set up a dot11req_mibset */
811 memset(&dot11req, 0, sizeof(p80211msg_dot11req_mibset_t));
812 dot11req.msgcode = DIDmsg_dot11req_mibset;
813 dot11req.msglen = sizeof(p80211msg_dot11req_mibset_t);
814 memcpy(dot11req.devname,
815 ((wlandevice_t*)(dev->priv))->name,
816 WLAN_DEVNAMELEN_MAX - 1);
817
818 /* Set up the mibattribute argument */
819 mibattr->did = DIDmsg_dot11req_mibset_mibattribute;
820 mibattr->status = P80211ENUM_msgitem_status_data_ok;
821 mibattr->len = sizeof(mibattr->data);
822
823 macaddr->did = DIDmib_dot11mac_dot11OperationTable_dot11MACAddress;
824 macaddr->status = P80211ENUM_msgitem_status_data_ok;
825 macaddr->len = sizeof(macaddr->data);
826 macaddr->data.len = WLAN_ADDR_LEN;
827 memcpy(&macaddr->data.data, new_addr->sa_data, WLAN_ADDR_LEN);
828
829 /* Set up the resultcode argument */
830 resultcode->did = DIDmsg_dot11req_mibset_resultcode;
831 resultcode->status = P80211ENUM_msgitem_status_no_value;
832 resultcode->len = sizeof(resultcode->data);
833 resultcode->data = 0;
834
835 /* now fire the request */
836 result = p80211req_dorequest(dev->priv, (UINT8*)&dot11req);
837
838 /* If the request wasn't successful, report an error and don't
839 * change the netdev address
840 */
841 if ( result != 0 || resultcode->data != P80211ENUM_resultcode_success) {
842 WLAN_LOG_ERROR(
843 "Low-level driver failed dot11req_mibset(dot11MACAddress).\n");
844 result = -EADDRNOTAVAIL;
845 } else {
846 /* everything's ok, change the addr in netdev */
847 memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
848 }
849
850 DBFEXIT;
851 return result;
852 }
853
854 static int wlan_change_mtu(netdevice_t *dev, int new_mtu)
855 {
856 DBFENTER;
857 // 2312 is max 802.11 payload, 20 is overhead, (ether + llc +snap)
858 // and another 8 for wep.
859 if ( (new_mtu < 68) || (new_mtu > (2312 - 20 - 8)))
860 return -EINVAL;
861
862 dev->mtu = new_mtu;
863
864 DBFEXIT;
865
866 return 0;
867 }
868
869
870
871 /*----------------------------------------------------------------
872 * wlan_setup
873 *
874 * Roughly matches the functionality of ether_setup. Here
875 * we set up any members of the wlandevice structure that are common
876 * to all devices. Additionally, we allocate a linux 'struct device'
877 * and perform the same setup as ether_setup.
878 *
879 * Note: It's important that the caller have setup the wlandev->name
880 * ptr prior to calling this function.
881 *
882 * Arguments:
883 * wlandev ptr to the wlandev structure for the
884 * interface.
885 * Returns:
886 * zero on success, non-zero otherwise.
887 * Call Context:
888 * Should be process thread. We'll assume it might be
889 * interrupt though. When we add support for statically
890 * compiled drivers, this function will be called in the
891 * context of the kernel startup code.
892 ----------------------------------------------------------------*/
893 int wlan_setup(wlandevice_t *wlandev)
894 {
895 int result = 0;
896 netdevice_t *dev;
897
898 DBFENTER;
899
900 /* Set up the wlandev */
901 wlandev->state = WLAN_DEVICE_CLOSED;
902 wlandev->ethconv = WLAN_ETHCONV_8021h;
903 wlandev->macmode = WLAN_MACMODE_NONE;
904
905 /* Set up the rx queue */
906 skb_queue_head_init(&wlandev->nsd_rxq);
907 tasklet_init(&wlandev->rx_bh,
908 p80211netdev_rx_bh,
909 (unsigned long)wlandev);
910
911 /* Allocate and initialize the struct device */
912 dev = kmalloc(sizeof(netdevice_t), GFP_ATOMIC);
913 if ( dev == NULL ) {
914 WLAN_LOG_ERROR("Failed to alloc netdev.\n");
915 result = 1;
916 } else {
917 memset( dev, 0, sizeof(netdevice_t));
918 ether_setup(dev);
919 wlandev->netdev = dev;
920 dev->priv = wlandev;
921 dev->hard_start_xmit = p80211knetdev_hard_start_xmit;
922 dev->get_stats = p80211knetdev_get_stats;
923 #ifdef HAVE_PRIVATE_IOCTL
924 dev->do_ioctl = p80211knetdev_do_ioctl;
925 #endif
926 #ifdef HAVE_MULTICAST
927 dev->set_multicast_list = p80211knetdev_set_multicast_list;
928 #endif
929 dev->init = p80211knetdev_init;
930 dev->open = p80211knetdev_open;
931 dev->stop = p80211knetdev_stop;
932
933 #ifdef CONFIG_NET_WIRELESS
934 #if ((WIRELESS_EXT < 17) && (WIRELESS_EXT < 21))
935 dev->get_wireless_stats = p80211wext_get_wireless_stats;
936 #endif
937 #if WIRELESS_EXT > 12
938 dev->wireless_handlers = &p80211wext_handler_def;
939 #endif
940 #endif
941
942 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,38) )
943 dev->tbusy = 1;
944 dev->start = 0;
945 #else
946 netif_stop_queue(dev);
947 #endif
948 #ifdef HAVE_CHANGE_MTU
949 dev->change_mtu = wlan_change_mtu;
950 #endif
951 #ifdef HAVE_SET_MAC_ADDR
952 dev->set_mac_address = p80211knetdev_set_mac_address;
953 #endif
954 #ifdef HAVE_TX_TIMEOUT
955 dev->tx_timeout = &p80211knetdev_tx_timeout;
956 dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000;
957 #endif
958 netif_carrier_off(dev);
959 }
960
961 DBFEXIT;
962 return result;
963 }
964
965 /*----------------------------------------------------------------
966 * wlan_unsetup
967 *
968 * This function is paired with the wlan_setup routine. It should
969 * be called after unregister_wlandev. Basically, all it does is
970 * free the 'struct device' that's associated with the wlandev.
971 * We do it here because the 'struct device' isn't allocated
972 * explicitly in the driver code, it's done in wlan_setup. To
973 * do the free in the driver might seem like 'magic'.
974 *
975 * Arguments:
976 * wlandev ptr to the wlandev structure for the
977 * interface.
978 * Returns:
979 * zero on success, non-zero otherwise.
980 * Call Context:
981 * Should be process thread. We'll assume it might be
982 * interrupt though. When we add support for statically
983 * compiled drivers, this function will be called in the
984 * context of the kernel startup code.
985 ----------------------------------------------------------------*/
986 int wlan_unsetup(wlandevice_t *wlandev)
987 {
988 int result = 0;
989
990 DBFENTER;
991
992 tasklet_kill(&wlandev->rx_bh);
993
994 if (wlandev->netdev == NULL ) {
995 WLAN_LOG_ERROR("called without wlandev->netdev set.\n");
996 result = 1;
997 } else {
998 free_netdev(wlandev->netdev);
999 wlandev->netdev = NULL;
1000 }
1001
1002 DBFEXIT;
1003 return 0;
1004 }
1005
1006
1007
1008 /*----------------------------------------------------------------
1009 * register_wlandev
1010 *
1011 * Roughly matches the functionality of register_netdev. This function
1012 * is called after the driver has successfully probed and set up the
1013 * resources for the device. It's now ready to become a named device
1014 * in the Linux system.
1015 *
1016 * First we allocate a name for the device (if not already set), then
1017 * we call the Linux function register_netdevice.
1018 *
1019 * Arguments:
1020 * wlandev ptr to the wlandev structure for the
1021 * interface.
1022 * Returns:
1023 * zero on success, non-zero otherwise.
1024 * Call Context:
1025 * Can be either interrupt or not.
1026 ----------------------------------------------------------------*/
1027 int register_wlandev(wlandevice_t *wlandev)
1028 {
1029 int i = 0;
1030 netdevice_t *dev = wlandev->netdev;
1031
1032 DBFENTER;
1033
1034 i = dev_alloc_name(wlandev->netdev, "wlan%d");
1035 if (i >= 0) {
1036 i = register_netdev(wlandev->netdev);
1037 }
1038 if (i != 0) {
1039 return -EIO;
1040 }
1041
1042 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) )
1043 dev->name = wlandev->name;
1044 #else
1045 strcpy(wlandev->name, dev->name);
1046 #endif
1047
1048 #ifdef CONFIG_PROC_FS
1049 if (proc_p80211) {
1050 wlandev->procdir = proc_mkdir(wlandev->name, proc_p80211);
1051 if ( wlandev->procdir )
1052 wlandev->procwlandev =
1053 create_proc_read_entry("wlandev", 0,
1054 wlandev->procdir,
1055 p80211netdev_proc_read,
1056 wlandev);
1057 if (wlandev->nsd_proc_read)
1058 create_proc_read_entry("nsd", 0,
1059 wlandev->procdir,
1060 wlandev->nsd_proc_read,
1061 wlandev);
1062 }
1063 #endif
1064
1065 #ifdef CONFIG_HOTPLUG
1066 p80211_run_sbin_hotplug(wlandev, WLAN_HOTPLUG_REGISTER);
1067 #endif
1068
1069 DBFEXIT;
1070 return 0;
1071 }
1072
1073
1074 /*----------------------------------------------------------------
1075 * unregister_wlandev
1076 *
1077 * Roughly matches the functionality of unregister_netdev. This
1078 * function is called to remove a named device from the system.
1079 *
1080 * First we tell linux that the device should no longer exist.
1081 * Then we remove it from the list of known wlan devices.
1082 *
1083 * Arguments:
1084 * wlandev ptr to the wlandev structure for the
1085 * interface.
1086 * Returns:
1087 * zero on success, non-zero otherwise.
1088 * Call Context:
1089 * Can be either interrupt or not.
1090 ----------------------------------------------------------------*/
1091 int unregister_wlandev(wlandevice_t *wlandev)
1092 {
1093 struct sk_buff *skb;
1094
1095 DBFENTER;
1096
1097 #ifdef CONFIG_HOTPLUG
1098 p80211_run_sbin_hotplug(wlandev, WLAN_HOTPLUG_REMOVE);
1099 #endif
1100
1101 #ifdef CONFIG_PROC_FS
1102 if ( wlandev->procwlandev ) {
1103 remove_proc_entry("wlandev", wlandev->procdir);
1104 }
1105 if ( wlandev->nsd_proc_read ) {
1106 remove_proc_entry("nsd", wlandev->procdir);
1107 }
1108 if (wlandev->procdir) {
1109 remove_proc_entry(wlandev->name, proc_p80211);
1110 }
1111 #endif
1112
1113 unregister_netdev(wlandev->netdev);
1114
1115 /* Now to clean out the rx queue */
1116 while ( (skb = skb_dequeue(&wlandev->nsd_rxq)) ) {
1117 dev_kfree_skb(skb);
1118 }
1119
1120 DBFEXIT;
1121 return 0;
1122 }
1123
1124 #ifdef CONFIG_PROC_FS
1125 /*----------------------------------------------------------------
1126 * proc_read
1127 *
1128 * Read function for /proc/net/p80211/<device>/wlandev
1129 *
1130 * Arguments:
1131 * buf
1132 * start
1133 * offset
1134 * count
1135 * eof
1136 * data
1137 * Returns:
1138 * zero on success, non-zero otherwise.
1139 * Call Context:
1140 * Can be either interrupt or not.
1141 ----------------------------------------------------------------*/
1142 static int
1143 p80211netdev_proc_read(
1144 char *page,
1145 char **start,
1146 off_t offset,
1147 int count,
1148 int *eof,
1149 void *data)
1150 {
1151 char *p = page;
1152 wlandevice_t *wlandev = (wlandevice_t *) data;
1153
1154 DBFENTER;
1155 if (offset != 0) {
1156 *eof = 1;
1157 goto exit;
1158 }
1159
1160 p += sprintf(p, "p80211 version: %s (%s)\n\n",
1161 WLAN_RELEASE, WLAN_BUILD_DATE);
1162 p += sprintf(p, "name : %s\n", wlandev->name);
1163 p += sprintf(p, "nsd name : %s\n", wlandev->nsdname);
1164 p += sprintf(p, "address : %02x:%02x:%02x:%02x:%02x:%02x\n",
1165 wlandev->netdev->dev_addr[0], wlandev->netdev->dev_addr[1], wlandev->netdev->dev_addr[2],
1166 wlandev->netdev->dev_addr[3], wlandev->netdev->dev_addr[4], wlandev->netdev->dev_addr[5]);
1167 p += sprintf(p, "nsd caps : %s%s%s%s%s%s%s%s%s%s\n",
1168 (wlandev->nsdcaps & P80211_NSDCAP_HARDWAREWEP) ? "wep_hw " : "",
1169 (wlandev->nsdcaps & P80211_NSDCAP_TIEDWEP) ? "wep_tied " : "",
1170 (wlandev->nsdcaps & P80211_NSDCAP_NOHOSTWEP) ? "wep_hw_only " : "",
1171 (wlandev->nsdcaps & P80211_NSDCAP_PBCC) ? "pbcc " : "",
1172 (wlandev->nsdcaps & P80211_NSDCAP_SHORT_PREAMBLE) ? "short_preamble " : "",
1173 (wlandev->nsdcaps & P80211_NSDCAP_AGILITY) ? "agility " : "",
1174 (wlandev->nsdcaps & P80211_NSDCAP_AP_RETRANSMIT) ? "ap_retransmit " : "",
1175 (wlandev->nsdcaps & P80211_NSDCAP_HWFRAGMENT) ? "hw_frag " : "",
1176 (wlandev->nsdcaps & P80211_NSDCAP_AUTOJOIN) ? "autojoin " : "",
1177 (wlandev->nsdcaps & P80211_NSDCAP_NOSCAN) ? "" : "scan ");
1178
1179
1180 p += sprintf(p, "bssid : %02x:%02x:%02x:%02x:%02x:%02x\n",
1181 wlandev->bssid[0], wlandev->bssid[1], wlandev->bssid[2],
1182 wlandev->bssid[3], wlandev->bssid[4], wlandev->bssid[5]);
1183
1184 p += sprintf(p, "Enabled : %s%s\n",
1185 (wlandev->shortpreamble) ? "short_preamble " : "",
1186 (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) ? "privacy" : "");
1187
1188
1189 exit:
1190 DBFEXIT;
1191 return (p - page);
1192 }
1193 #endif
1194
1195 /*----------------------------------------------------------------
1196 * p80211netdev_hwremoved
1197 *
1198 * Hardware removed notification. This function should be called
1199 * immediately after an MSD has detected that the underlying hardware
1200 * has been yanked out from under us. The primary things we need
1201 * to do are:
1202 * - Mark the wlandev
1203 * - Prevent any further traffic from the knetdev i/f
1204 * - Prevent any further requests from mgmt i/f
1205 * - If there are any waitq'd mgmt requests or mgmt-frame exchanges,
1206 * shut them down.
1207 * - Call the MSD hwremoved function.
1208 *
1209 * The remainder of the cleanup will be handled by unregister().
1210 * Our primary goal here is to prevent as much tickling of the MSD
1211 * as possible since the MSD is already in a 'wounded' state.
1212 *
1213 * TODO: As new features are added, this function should be
1214 * updated.
1215 *
1216 * Arguments:
1217 * wlandev WLAN network device structure
1218 * Returns:
1219 * nothing
1220 * Side effects:
1221 *
1222 * Call context:
1223 * Usually interrupt.
1224 ----------------------------------------------------------------*/
1225 void p80211netdev_hwremoved(wlandevice_t *wlandev)
1226 {
1227 DBFENTER;
1228 wlandev->hwremoved = 1;
1229 if ( wlandev->state == WLAN_DEVICE_OPEN) {
1230 p80211netdev_stop_queue(wlandev);
1231 }
1232
1233 netif_device_detach(wlandev->netdev);
1234
1235 DBFEXIT;
1236 }
1237
1238
1239 /*----------------------------------------------------------------
1240 * p80211_rx_typedrop
1241 *
1242 * Classifies the frame, increments the appropriate counter, and
1243 * returns 0|1|2 indicating whether the driver should handle, ignore, or
1244 * drop the frame
1245 *
1246 * Arguments:
1247 * wlandev wlan device structure
1248 * fc frame control field
1249 *
1250 * Returns:
1251 * zero if the frame should be handled by the driver,
1252 * one if the frame should be ignored
1253 * anything else means we drop it.
1254 *
1255 * Side effects:
1256 *
1257 * Call context:
1258 * interrupt
1259 ----------------------------------------------------------------*/
1260 static int p80211_rx_typedrop( wlandevice_t *wlandev, UINT16 fc)
1261 {
1262 UINT16 ftype;
1263 UINT16 fstype;
1264 int drop = 0;
1265 /* Classify frame, increment counter */
1266 ftype = WLAN_GET_FC_FTYPE(fc);
1267 fstype = WLAN_GET_FC_FSTYPE(fc);
1268 #if 0
1269 WLAN_LOG_DEBUG(4,
1270 "rx_typedrop : ftype=%d fstype=%d.\n", ftype, fstype);
1271 #endif
1272 switch ( ftype ) {
1273 case WLAN_FTYPE_MGMT:
1274 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1275 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1276 drop = 1;
1277 break;
1278 }
1279 WLAN_LOG_DEBUG(3, "rx'd mgmt:\n");
1280 wlandev->rx.mgmt++;
1281 switch( fstype ) {
1282 case WLAN_FSTYPE_ASSOCREQ:
1283 /* printk("assocreq"); */
1284 wlandev->rx.assocreq++;
1285 break;
1286 case WLAN_FSTYPE_ASSOCRESP:
1287 /* printk("assocresp"); */
1288 wlandev->rx.assocresp++;
1289 break;
1290 case WLAN_FSTYPE_REASSOCREQ:
1291 /* printk("reassocreq"); */
1292 wlandev->rx.reassocreq++;
1293 break;
1294 case WLAN_FSTYPE_REASSOCRESP:
1295 /* printk("reassocresp"); */
1296 wlandev->rx.reassocresp++;
1297 break;
1298 case WLAN_FSTYPE_PROBEREQ:
1299 /* printk("probereq"); */
1300 wlandev->rx.probereq++;
1301 break;
1302 case WLAN_FSTYPE_PROBERESP:
1303 /* printk("proberesp"); */
1304 wlandev->rx.proberesp++;
1305 break;
1306 case WLAN_FSTYPE_BEACON:
1307 /* printk("beacon"); */
1308 wlandev->rx.beacon++;
1309 break;
1310 case WLAN_FSTYPE_ATIM:
1311 /* printk("atim"); */
1312 wlandev->rx.atim++;
1313 break;
1314 case WLAN_FSTYPE_DISASSOC:
1315 /* printk("disassoc"); */
1316 wlandev->rx.disassoc++;
1317 break;
1318 case WLAN_FSTYPE_AUTHEN:
1319 /* printk("authen"); */
1320 wlandev->rx.authen++;
1321 break;
1322 case WLAN_FSTYPE_DEAUTHEN:
1323 /* printk("deauthen"); */
1324 wlandev->rx.deauthen++;
1325 break;
1326 default:
1327 /* printk("unknown"); */
1328 wlandev->rx.mgmt_unknown++;
1329 break;
1330 }
1331 /* printk("\n"); */
1332 drop = 2;
1333 break;
1334
1335 case WLAN_FTYPE_CTL:
1336 if ((wlandev->netdev->flags & IFF_PROMISC) ||
1337 (wlandev->netdev->flags & IFF_ALLMULTI)) {
1338 drop = 1;
1339 break;
1340 }
1341 WLAN_LOG_DEBUG(3, "rx'd ctl:\n");
1342 wlandev->rx.ctl++;
1343 switch( fstype ) {
1344 case WLAN_FSTYPE_PSPOLL:
1345 /* printk("pspoll"); */
1346 wlandev->rx.pspoll++;
1347 break;
1348 case WLAN_FSTYPE_RTS:
1349 /* printk("rts"); */
1350 wlandev->rx.rts++;
1351 break;
1352 case WLAN_FSTYPE_CTS:
1353 /* printk("cts"); */
1354 wlandev->rx.cts++;
1355 break;
1356 case WLAN_FSTYPE_ACK:
1357 /* printk("ack"); */
1358 wlandev->rx.ack++;
1359 break;
1360 case WLAN_FSTYPE_CFEND:
1361 /* printk("cfend"); */
1362 wlandev->rx.cfend++;
1363 break;
1364 case WLAN_FSTYPE_CFENDCFACK:
1365 /* printk("cfendcfack"); */
1366 wlandev->rx.cfendcfack++;
1367 break;
1368 default:
1369 /* printk("unknown"); */
1370 wlandev->rx.ctl_unknown++;
1371 break;
1372 }
1373 /* printk("\n"); */
1374 drop = 2;
1375 break;
1376
1377 case WLAN_FTYPE_DATA:
1378 wlandev->rx.data++;
1379 switch( fstype ) {
1380 case WLAN_FSTYPE_DATAONLY:
1381 wlandev->rx.dataonly++;
1382 break;
1383 case WLAN_FSTYPE_DATA_CFACK:
1384 wlandev->rx.data_cfack++;
1385 break;
1386 case WLAN_FSTYPE_DATA_CFPOLL:
1387 wlandev->rx.data_cfpoll++;
1388 break;
1389 case WLAN_FSTYPE_DATA_CFACK_CFPOLL:
1390 wlandev->rx.data__cfack_cfpoll++;
1391 break;
1392 case WLAN_FSTYPE_NULL:
1393 WLAN_LOG_DEBUG(3, "rx'd data:null\n");
1394 wlandev->rx.null++;
1395 break;
1396 case WLAN_FSTYPE_CFACK:
1397 WLAN_LOG_DEBUG(3, "rx'd data:cfack\n");
1398 wlandev->rx.cfack++;
1399 break;
1400 case WLAN_FSTYPE_CFPOLL:
1401 WLAN_LOG_DEBUG(3, "rx'd data:cfpoll\n");
1402 wlandev->rx.cfpoll++;
1403 break;
1404 case WLAN_FSTYPE_CFACK_CFPOLL:
1405 WLAN_LOG_DEBUG(3, "rx'd data:cfack_cfpoll\n");
1406 wlandev->rx.cfack_cfpoll++;
1407 break;
1408 default:
1409 /* printk("unknown"); */
1410 wlandev->rx.data_unknown++;
1411 break;
1412 }
1413
1414 break;
1415 }
1416 return drop;
1417 }
1418
1419 #ifdef CONFIG_HOTPLUG
1420 /* Notify userspace when a netdevice event occurs,
1421 * by running '/sbin/hotplug net' with certain
1422 * environment variables set.
1423 */
1424 int p80211_run_sbin_hotplug(wlandevice_t *wlandev, char *action)
1425 {
1426 char *argv[3], *envp[7], ifname[12 + IFNAMSIZ], action_str[32];
1427 char nsdname[32], wlan_wext[32];
1428 int i;
1429
1430 if (wlandev) {
1431 sprintf(ifname, "INTERFACE=%s", wlandev->name);
1432 sprintf(nsdname, "NSDNAME=%s", wlandev->nsdname);
1433 } else {
1434 sprintf(ifname, "INTERFACE=null");
1435 sprintf(nsdname, "NSDNAME=null");
1436 }
1437
1438 sprintf(wlan_wext, "WLAN_WEXT=%s", wlan_wext_write ? "y" : "");
1439 sprintf(action_str, "ACTION=%s", action);
1440
1441 i = 0;
1442 argv[i++] = hotplug_path;
1443 argv[i++] = "wlan";
1444 argv[i] = NULL;
1445
1446 i = 0;
1447 /* minimal command environment */
1448 envp [i++] = "HOME=/";
1449 envp [i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
1450 envp [i++] = ifname;
1451 envp [i++] = action_str;
1452 envp [i++] = nsdname;
1453 envp [i++] = wlan_wext;
1454 envp [i] = NULL;
1455
1456 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,62))
1457 return call_usermodehelper(argv [0], argv, envp);
1458 #else
1459 return call_usermodehelper(argv [0], argv, envp, 0);
1460 #endif
1461 }
1462
1463 #endif
1464
1465
1466 void p80211_suspend(wlandevice_t *wlandev)
1467 {
1468 DBFENTER;
1469
1470 #ifdef CONFIG_HOTPLUG
1471 p80211_run_sbin_hotplug(wlandev, WLAN_HOTPLUG_SUSPEND);
1472 #endif
1473
1474 DBFEXIT;
1475 }
1476
1477 void p80211_resume(wlandevice_t *wlandev)
1478 {
1479 DBFENTER;
1480
1481 #ifdef CONFIG_HOTPLUG
1482 p80211_run_sbin_hotplug(wlandev, WLAN_HOTPLUG_RESUME);
1483 #endif
1484
1485 DBFEXIT;
1486 }
1487
1488 static void p80211knetdev_tx_timeout( netdevice_t *netdev)
1489 {
1490 wlandevice_t *wlandev = (wlandevice_t*)netdev->priv;
1491 DBFENTER;
1492
1493 if (wlandev->tx_timeout) {
1494 wlandev->tx_timeout(wlandev);
1495 } else {
1496 WLAN_LOG_WARNING("Implement tx_timeout for %s\n",
1497 wlandev->nsdname);
1498 p80211netdev_wake_queue(wlandev);
1499 }
1500
1501 DBFEXIT;
1502 }
This page took 0.082467 seconds and 5 git commands to generate.