| 1 |
#!/bin/sh |
| 2 |
# Paul Sladen, 2006-03-28, 2007-03-26 |
| 3 |
# Library functions to check/change status of wireless |
| 4 |
|
| 5 |
# Return 0 if there is, allowing you to write if isAnyWirelessPoweredOn; then ... |
| 6 |
isAnyWirelessPoweredOn() |
| 7 |
{ |
| 8 |
for DEVICE in /sys/class/net/* ; do |
| 9 |
if [ -d $DEVICE/wireless ]; then |
| 10 |
for RFKILL in $DEVICE/phy80211/rfkill*/state $DEVICE/device/rfkill/rfkill*/state |
| 11 |
do |
| 12 |
if [ -r "$RFKILL" ] && [ "$(cat "$RFKILL")" -eq 1 ] |
| 13 |
then |
| 14 |
return 0 |
| 15 |
fi |
| 16 |
done |
| 17 |
# if any of the wireless devices are turned on then return success |
| 18 |
if [ -r $DEVICE/device/power/state ] && [ "`cat $DEVICE/device/power/state`" -eq 0 ] |
| 19 |
then |
| 20 |
return 0 |
| 21 |
fi |
| 22 |
if [ -r $DEVICE/device/rf_kill ] && [ "`cat $DEVICE/device/rf_kill`" -eq 0 ] |
| 23 |
then |
| 24 |
return 0 |
| 25 |
fi |
| 26 |
fi |
| 27 |
done |
| 28 |
|
| 29 |
# otherwise return failure |
| 30 |
return 1 |
| 31 |
} |
| 32 |
|
| 33 |
# Takes no parameters, toggles all wireless devices. |
| 34 |
# TODO: Should possible toggle all wireless devices to the state of the first one. |
| 35 |
# Attempts to use 'rf_kill' first, and then tries 'power/state', though that |
| 36 |
# will fail on >=2.6.18 kernels since upstream removed the functionality... |
| 37 |
toggleAllWirelessStates() |
| 38 |
{ |
| 39 |
for DEVICE in /sys/class/net/* ; do |
| 40 |
if [ -d $DEVICE/wireless ] ; then |
| 41 |
# $DEVICE is a wireless device. |
| 42 |
|
| 43 |
FOUND= |
| 44 |
# Yes, that's right... the new interface reverses the truth values. |
| 45 |
ON=1 |
| 46 |
OFF=0 |
| 47 |
for CONTROL in $DEVICE/device/rfkill/rfkill*/state; do |
| 48 |
if [ -w "$CONTROL" ]; then |
| 49 |
FOUND=1 |
| 50 |
|
| 51 |
if [ "$(cat "$CONTROL")" = "$ON" ] ; then |
| 52 |
# It's powered on. Switch it off. |
| 53 |
echo -n "$OFF" > "$CONTROL" |
| 54 |
else |
| 55 |
# It's powered off. Switch it on. |
| 56 |
echo -n "$ON" > "$CONTROL" |
| 57 |
fi |
| 58 |
fi |
| 59 |
done |
| 60 |
# it might be safe to assume that a device only supports one |
| 61 |
# interface at a time; but just in case, we short-circuit |
| 62 |
# here to avoid toggling the power twice |
| 63 |
if [ -n "$FOUND" ]; then |
| 64 |
continue |
| 65 |
fi |
| 66 |
|
| 67 |
ON=0 |
| 68 |
OFF=1 # 1 for rf_kill, 2 for power/state |
| 69 |
for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do |
| 70 |
if [ -w $CONTROL ] ; then |
| 71 |
# We have a way of controlling the device, lets try |
| 72 |
if [ "`cat $CONTROL`" = 0 ] ; then |
| 73 |
# It's powered on. Switch it off. |
| 74 |
if echo -n $OFF > $CONTROL ; then |
| 75 |
break |
| 76 |
else |
| 77 |
OFF=2 # for power/state, second time around |
| 78 |
fi |
| 79 |
else |
| 80 |
# It's powered off. Switch it on. |
| 81 |
if echo -n $ON > $CONTROL ; then |
| 82 |
break |
| 83 |
fi |
| 84 |
fi |
| 85 |
fi |
| 86 |
done |
| 87 |
fi |
| 88 |
done |
| 89 |
} |
| 90 |
|
| 91 |
# Pass '1' to blink suspending LED and '0' to stop LED |
| 92 |
setLEDThinkpadSuspending() |
| 93 |
{ |
| 94 |
action=`test "$1" -ne 0 && echo blink || echo off` |
| 95 |
test -w /proc/acpi/ibm/led && echo -n 7 "$action" > /proc/acpi/ibm/led |
| 96 |
} |