Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | kardasa | 1 | #Function to toggle wireless interfaces originaly created by Paul Sladen for Ubuntu acpi-support package |
2 | for DEVICE in /sys/class/net/* ; do |
||
3 | if [ -d $DEVICE/wireless ] ; then |
||
4 | # $DEVICE is a wireless device. |
||
5 | |||
6 | FOUND= |
||
7 | # Yes, that's right... the new interface reverses the truth values. |
||
8 | ON=1 |
||
9 | OFF=0 |
||
10 | for CONTROL in $DEVICE/device/rfkill/rfkill*/state; do |
||
11 | if [ -w "$CONTROL" ]; then |
||
12 | FOUND=1 |
||
13 | |||
14 | if [ "$(cat "$CONTROL")" = "$ON" ] ; then |
||
15 | # It's powered on. Switch it off. |
||
16 | echo -n "$OFF" > "$CONTROL" |
||
17 | else |
||
18 | # It's powered off. Switch it on. |
||
19 | echo -n "$ON" > "$CONTROL" |
||
20 | fi |
||
21 | fi |
||
22 | done |
||
23 | # it might be safe to assume that a device only supports one |
||
24 | # interface at a time; but just in case, we short-circuit |
||
25 | # here to avoid toggling the power twice |
||
26 | if [ -n "$FOUND" ]; then |
||
27 | continue |
||
28 | fi |
||
29 | |||
30 | ON=0 |
||
31 | OFF=1 # 1 for rf_kill, 2 for power/state |
||
32 | for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do |
||
33 | if [ -w $CONTROL ] ; then |
||
34 | # We have a way of controlling the device, lets try |
||
35 | if [ "`cat $CONTROL`" = 0 ] ; then |
||
36 | # It's powered on. Switch it off. |
||
37 | if echo -n $OFF > $CONTROL ; then |
||
38 | break |
||
39 | else |
||
40 | OFF=2 # for power/state, second time around |
||
41 | fi |
||
42 | else |
||
43 | # It's powered off. Switch it on. |
||
44 | if echo -n $ON > $CONTROL ; then |
||
45 | break |
||
46 | fi |
||
47 | fi |
||
48 | fi |
||
49 | done |
||
50 | fi |
||
51 | done |