wl1251: Add support for idle mode
[pandora-wifi.git] / scripts / madwifi-unload
1 #!/bin/sh
2 # Copyright 2006        Kel Modderman <kelrin@tpg.com.au>
3
4 # Taken from madwifi scripts. This unloads madwifi
5
6 : ${PATTERN='\(ath_.*\|wlan_.*\|wlan\)$'}
7 : ${MAX_TRIES=10}
8
9 test "`id -u`" = 0 || {
10         echo "ERROR: You must be root to run this script" >&2
11         exit 1
12 }
13
14 test -r /proc/modules || {
15         echo "ERROR: Cannot read /proc/modules" >&2
16         exit 1
17 }
18
19 tries="$MAX_TRIES"
20 while test "$tries" != "0"; do
21         skipped=0
22         IFS='
23 '
24         for line in `cat /proc/modules`; do
25                 IFS='   '
26                 set x $line
27                 name="$2"
28                 size="$3"
29                 use_count="$4"
30                 use_name="$5"
31                 state="$6"
32                 expr "$name" : "$PATTERN" >/dev/null || continue
33
34                 # Compatibility for Linux 2.4.x
35                 test -z "$state" && { use_name="-"; state="Live"; }
36
37                 if test "$state" != "Live" || test "$use_count" != "0" || \
38                    test "$use_name" != "-"; then
39                         # Don't skip unload in the last run
40                         if test "$tries" != "1"; then
41                                 skipped=1
42                                 continue
43                         fi
44                 fi
45
46                 echo "Unloading \"$name\""
47                 sync    # to be safe
48                 /sbin/rmmod "$name" || {
49                         echo "ERROR: cannot unload module \"$name\"" >&2
50                         exit 1
51                 }
52                 sync    # to be even safer
53         done
54         test "$skipped" = "0" && break
55         tries=$(($tries - 1))
56 done
57
58 exit 0