# Paul Sladen, 2006-03-28, 2007-03-26 # Luca Niccoli , 2010-06-23 # Cristian Ionescu-Idbohrn , 2010-12-14 # Library functions to check/change status of wireless # Setup WLAN_RFKILLS list WLAN_RFKILLS= for r in /sys/class/rfkill/rfkill*; do ! read t <$r/type || [ "$t" != wlan ] || WLAN_RFKILLS=${WLAN_RFKILLS:+$WLAN_RFKILLS }$r/state done haveDevRfkill() { [ -c /dev/rfkill ] && [ -x /usr/sbin/rfkill ] } isAnyWirelessPoweredOn() { local RFKILL s if haveDevRfkill; then rfkill list wlan | egrep -q "Soft[[:blank:]]+blocked:[[:blank:]]+no" return $? else for RFKILL in $WLAN_RFKILLS ; do [ ! -r "$RFKILL" ] || ! read s <$RFKILL || [ "$s" -ne 1 ] || return 0 done fi # otherwise return failure return 1 } # Takes no parameters, toggles all wireless devices. toggleAllWirelessStates() { local WIFACE RFKILL get_wifaces zzz=0 max_zzz=7 local wicd_connect=/usr/share/wicd/daemon/autoconnect.py if [ -x /usr/sbin/iw ]; then get_wifaces='iw dev | sed -rne "s|^[[:blank:]]+Interface[[:blank:]]+([[:alnum:]]+).*$|\1|p"' elif [ -x /sbin/iwconfig ]; then get_wifaces='iwconfig 2>/dev/null | grep -o "^[[:alnum:]]*"' else logger -t${0##*/} -perr -- \ toggleAllWirelessStates: no way to pick up interfaces exit 1 fi if [ -x /sbin/ip ]; then if_cmd="ip link set dev" elif [ -x /sbin/ifconfig ]; then if_cmd=ifconfig else logger -t${0##*/} -perr -- \ toggleAllWirelessStates: no way to up/down interfaces exit 1 fi # If rfkill is handled by the kernel, don't touch it if ! grep -q '^H.*\brfkill\b' /proc/bus/input/devices; then if isAnyWirelessPoweredOn; then # 'down'ing wireless interfaces, helps with some # buggy drivers for WIFACE in $(eval $get_wifaces); do $if_cmd $WIFACE down 2>/dev/null || : done if haveDevRfkill; then rfkill block wlan else for RFKILL in $WLAN_RFKILLS; do [ ! -w $RFKILL ] || echo 0 >$RFKILL done fi else if haveDevRfkill; then rfkill unblock wlan else for RFKILL in $WLAN_RFKILLS; do [ ! -w $RFKILL ] || echo 1 >$RFKILL done fi fi fi # Is wireless on now? Set the interfaces up and poke wicd while ! isAnyWirelessPoweredOn && [ $zzz -lt $max_zzz ]; do sleep 1 zzz=$(($zzz + 1)) done if [ $zzz -lt $max_zzz ]; then for WIFACE in $(eval $get_wifaces); do $if_cmd $WIFACE up 2>/dev/null || : done [ ! -x $wicd_connect ] || $wicd_connect fi } # Pass '1' to blink suspending LED and '0' to stop LED setLEDThinkpadSuspending() { local ibm_led=/proc/acpi/ibm/led action=$([ "$1" -ne 0 ] && echo blink || echo off) [ ! -w $ibm_led ] || printf '7 %s' $action >$ibm_led }