/usr/lib/pm-utils/power.d/wireless is in pm-utils 1.4.1-17.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #!/bin/sh
. "${PM_FUNCTIONS}"
# See if we have the usual wireless tools.
# Do not just fail because not all cards require these.
which iwpriv >/dev/null 2>&1 && have_iwpriv="true"
which iwconfig >/dev/null 2>&1 && have_iwconfig="true"
# If only all the drivers did The Right Thing with iwconfig power.
# Too bad they do not.
get_wireless_params() {
# $1 = interface
# $2 = on or off
unset iwpriv iwconfig iwlevel
# Don't do anything if we cannot find a driver for this iface.
[ -L "/sys/class/net/$1/device/driver" ] || return 1
# Skip if not a wireless card.
[ -d "/sys/class/net/$1/wireless" ] || return 1
# Also don't do anything if the device is disabled
[ "$(cat /sys/class/net/$1/device/enable* 2>/dev/null)" != "0" ] || return 1
driver="$(readlink "/sys/class/net/$1/device/driver")"
driver=${driver##*/}
case $driver in
ipw2100) iwpriv_ac="set_power 0"
iwpriv_batt="set_power 5"
iwconfig_ac="power on"
iwconfig_batt="power on";;
ipw3945)
iwpriv_ac="set_power 6"
iwpriv_batt="set_power 7";;
iwl*) if [ -f "/sys/class/net/$1/device/power_level" ]; then
iwlevel_ac=0
iwlevel_batt=3
else
iwconfig_ac="power off"
iwconfig_batt="power on"
fi;;
*) iwconfig_ac="power off"
iwconfig_batt="power on";;
esac
case $2 in
off) [ "$iwpriv_ac" ] && iwpriv="$iwpriv_ac"
[ "$iwconfig_ac" ] && iwconfig="$iwconfig_ac"
[ "$iwlevel_ac" ] && iwlevel="$iwlevel_ac";;
on) [ "$iwpriv_batt" ] && iwpriv="$iwpriv_batt"
[ "$iwconfig_batt" ] && iwconfig="$iwconfig_batt"
[ "$iwlevel_batt" ] && iwlevel="$iwlevel_batt";;
esac
return 0
}
wireless_powersave() {
for dev in /sys/class/net/*; do
get_wireless_params "${dev##*/}" "$1" || continue
ret=0
printf "Turning powersave for %s %s..." "${dev##*/}" "$1"
if [ "$have_iwconfig" = true -a "$iwconfig" ]; then
iwconfig "${dev##*/}" $iwconfig || ret=1
fi
if [ "$have_iwpriv" = true -a "$iwpriv" ]; then
iwpriv "${dev##*/}" $iwpriv || ret=1
fi
if [ "$iwlevel" ]; then
echo "$iwlevel" > "$dev/device/power_level" || ret=1
fi
[ "$ret" -eq 0 ] && echo Done. || echo Failed.
done
}
case $1 in
true) wireless_powersave on ;;
false) wireless_powersave off ;;
*) exit $NA ;;
esac
exit 0
|