Skip to content

Commit

Permalink
Merge pull request #30 from shuber2/ethernet-poweroff
Browse files Browse the repository at this point in the history
Ethernet poweroff
  • Loading branch information
rickysarraf committed May 27, 2014
2 parents 64e8a82 + 8fff5eb commit e77c42c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 49 deletions.
13 changes: 6 additions & 7 deletions etc/laptop-mode/conf.d/ethernet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DEBUG=0
# Control Ethernet settings?
CONTROL_ETHERNET="auto"

# Handle throttling of the ethernet deivce under specific circumstances
# Handle throttling of the ethernet device under specific circumstances
BATT_THROTTLE_ETHERNET=1
LM_AC_THROTTLE_ETHERNET=0
NOLM_AC_THROTTLE_ETHERNET=0
Expand Down Expand Up @@ -60,11 +60,10 @@ ETHERNET_DEVICES="eth0"


# In practise, most of the times a user is on battery, she is using the wireless device
# Under such cases, you might want to disable your ethernet device completely, when
# Under such cases, you might want to disable your ethernet interface completely, when
# on battery.
#
# NOTE: This feature heavily depends on functionality from the device driver, often disabled,
# by default. Please consult your driver documentation to ensure you have the feature enabled
#
# Set below setting to 1, to disable ethernet device when on batter
DISABLE_ETHERNET_ON_BATTERY=0
# Set below setting to 1, to disable ethernet interface when on battery and
# when no carrier is detected on the interface (e.g., no active cable is
# plugged in).
DISABLE_ETHERNET_ON_BATTERY=1
64 changes: 22 additions & 42 deletions usr/share/laptop-mode-tools/modules/ethernet
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHE
MIITOOL=/bin/false
fi

if [ -x /bin/ip ]; then
IPTOOL=/bin/ip
else
log "VERBOSE" "ip is not installed"
IPTOOL=/bin/false
fi


if [ $ON_AC -eq 1 ]; then
if [ "$ACTIVATE" -eq 1 ]; then
Expand Down Expand Up @@ -52,48 +59,7 @@ if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHE
fi

for DEVICE in $ETHERNET_DEVICES ; do
DISABLED=0
path=`readlink -f /sys/class/net/$DEVICE`
dev_path=""
log "VERBOSE" "ethernet: $path"
if ! [ -z $path ]; then
if [ -d $path/device ]; then
dev_path=`readlink -f $path/device`
log "VERBOSE" "ethernet: $dev_path"
fi
fi

dev_enable_path=
if [ x$dev_path != x ]; then
if [ -f $dev_path/enabled ]; then
dev_enable_path=$dev_path/enabled
elif [ -f $dev_path/enable ]; then
dev_enable_path=$dev_path/enable
fi
fi

if [ x$dev_enable_path != x ]; then
if [ x$DISABLE_ETHERNET = x1 ]; then
echo 0 > $dev_enable_path 2>/dev/null
log "VERBOSE" "ethernet: Disabling ethernet device $DEVICE"
DISABLED=1
elif [ x$DISABLE_ETHERNET = x0 ]; then
echo 1 > $dev_enable_path 2>/dev/null
log "VERBOSE" "ethernet: Re-enabling ethernet device $DEVICE"
DISABLED=0
elif [ x$DISABLE_ETHERNET = x2 ]; then
DISABLED=0 # Be safe. :-)
else
DISABLED=0 # Same here. Be safe. :-)
# For all other cases also, just disable it.
fi
else
log "VERBOSE" "$DEVICE does not seem to be supporting enable/disable"
fi

if [ x$DISABLED = x1 ]; then
continue
fi
log "VERBOSE" "ethernet: $DEVICE"

# Wakeup-on-LAN handling
if [ x$DISABLE_WAKEUP_ON_LAN = x1 ] ; then
Expand Down Expand Up @@ -157,6 +123,20 @@ if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHE
log "VERBOSE" "Could not restore speed for $DEVICE"
fi
fi

# Shut down interface
if [ x$DISABLE_ETHERNET = x1 ]; then
if $IPTOOL link show $DEVICE | grep -q NO-CARRIER; then
log "VERBOSE" "ethernet: Disabling ethernet device $DEVICE"
$IPTOOL link set dev $DEVICE down
else
log "VERBOSE" "ethernet: Not disabling ethernet device $DEVICE with active carrier."
fi
elif [ x$DISABLE_ETHERNET = x0 ]; then
$IPTOOL link set dev $DEVICE up
log "VERBOSE" "ethernet: Re-enabling ethernet device $DEVICE"
fi

done
else
log "VERBOSE" "Ethernet module is disabled."
Expand Down

0 comments on commit e77c42c

Please sign in to comment.