Debian Codegraph @

lib/state-funcs

raw ◀ ▶
1 Debian patch touch this file
1 # Paul Sladen, 2006-03-28, 2007-03-26
•2 # Luca Niccoli <[email protected]>, 2010-06-23
3 # Cristian Ionescu-Idbohrn <[email protected]>, 2010-12-14
4 # Library functions to check/change status of wireless
5
•6 # Setup WLAN_RFKILLS list
7 WLAN_RFKILLS=
8 for r in /sys/class/rfkill/rfkill*; do
9 ! read t <$r/type || [ "$t" != wlan ] ||
10 WLAN_RFKILLS=${WLAN_RFKILLS:+$WLAN_RFKILLS }$r/state
11 done
12
•13 haveDevRfkill() {
14 [ -c /dev/rfkill ] && [ -x /usr/sbin/rfkill ]
15 }
16
17 isAnyWirelessPoweredOn() {
18 local RFKILL s
19
20 if haveDevRfkill; then
21 rfkill list wlan |
22 egrep -q "Soft[[:blank:]]+blocked:[[:blank:]]+no"
23 return $?
24 else
25 for RFKILL in $WLAN_RFKILLS ; do
26 [ ! -r "$RFKILL" ] || ! read s <$RFKILL ||
27 [ "$s" -ne 1 ] || return 0
28 done
29 fi
30 # otherwise return failure
31 return 1
32 }
33
34 # Takes no parameters, toggles all wireless devices.
•35 toggleAllWirelessStates() {
36 local WIFACE RFKILL get_wifaces zzz=0 max_zzz=7
37 local wicd_connect=/usr/share/wicd/daemon/autoconnect.py
38
39 if [ -x /usr/sbin/iw ]; then
40 get_wifaces='iw dev | sed -rne "s|^[[:blank:]]+Interface[[:blank:]]+([[:alnum:]]+).*$|\1|p"'
41 elif [ -x /sbin/iwconfig ]; then
42 get_wifaces='iwconfig 2>/dev/null | grep -o "^[[:alnum:]]*"'
43 else
44 logger -t${0##*/} -perr -- \
45 toggleAllWirelessStates: no way to pick up interfaces
46 exit 1
47 fi
48
49 if [ -x /sbin/ip ]; then
50 if_cmd="ip link set dev"
51 elif [ -x /sbin/ifconfig ]; then
52 if_cmd=ifconfig
53 else
54 logger -t${0##*/} -perr -- \
55 toggleAllWirelessStates: no way to up/down interfaces
56 exit 1
57 fi
58
59 # If rfkill is handled by the kernel, don't touch it
60 if ! grep -q '^H.*\brfkill\b' /proc/bus/input/devices; then
61 if isAnyWirelessPoweredOn; then
62 # 'down'ing wireless interfaces, helps with some
63 # buggy drivers
64 for WIFACE in $(eval $get_wifaces); do
65 $if_cmd $WIFACE down 2>/dev/null || :
66 done
67 if haveDevRfkill; then
68 rfkill block wlan
69 else
•70 for RFKILL in $WLAN_RFKILLS; do
71 [ ! -w $RFKILL ] || echo 0 >$RFKILL
72 done
73 fi
•74 else
75 if haveDevRfkill; then
76 rfkill unblock wlan
77 else
78 for RFKILL in $WLAN_RFKILLS; do
79 [ ! -w $RFKILL ] || echo 1 >$RFKILL
80 done
81 fi
82 fi
83 fi
•84 # Is wireless on now? Set the interfaces up and poke wicd
85 while ! isAnyWirelessPoweredOn && [ $zzz -lt $max_zzz ]; do
86 sleep 1
87 zzz=$(($zzz + 1))
88 done
89 if [ $zzz -lt $max_zzz ]; then
90 for WIFACE in $(eval $get_wifaces); do
91 $if_cmd $WIFACE up 2>/dev/null || :
92 done
93 [ ! -x $wicd_connect ] || $wicd_connect
94 fi
95 }
96
97 # Pass '1' to blink suspending LED and '0' to stop LED
•98 setLEDThinkpadSuspending() {
99 local ibm_led=/proc/acpi/ibm/led
100
101 action=$([ "$1" -ne 0 ] && echo blink || echo off)
102 [ ! -w $ibm_led ] || printf '7 %s' $action >$ibm_led
103 }