home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / ethernet < prev    next >
Encoding:
Text File  |  2012-05-20  |  5.2 KB  |  159 lines

  1. #! /bin/sh
  2. # Laptop mode tools module: Ethernet power saving tweaks.
  3. #
  4.  
  5. if [ x$CONTROL_ETHERNET = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_ETHERNET = xauto ]; then
  6.     if [ $ON_AC -eq 1 ]; then
  7.         if [ "$ACTIVATE" -eq 1 ]; then
  8.             THROTTLE_ETHERNET="$LM_AC_THROTTLE_ETHERNET"
  9.         else
  10.             THROTTLE_ETHERNET="$NOLM_AC_THROTTLE_ETHERNET"
  11.         fi
  12.  
  13.                 if [ x$DISABLE_ETHERNET_ON_BATTERY = x1 ]; then
  14.                         # We are ON_AC and Disable feature is requested
  15.                         # So we might be required to re-enable the device.
  16.                         DISABLE_ETHERNET=0 #zero would mean that the device needs be re-enabled.
  17.                 else
  18.                         DISABLE_ETHERNET=2
  19.                         # IF this is the case, don't touch the device for
  20.                         # enable/disable
  21.                 fi
  22.     else
  23.         THROTTLE_ETHERNET="$BATT_THROTTLE_ETHERNET"
  24.  
  25.                 if [ x$DISABLE_ETHERNET_ON_BATTERY = x1 ]; then
  26.                         DISABLE_ETHERNET=1
  27.                 else
  28.                         DISABLE_ETHERNET=2
  29.                 fi
  30.     fi
  31.     
  32.     for DEVICE in $ETHERNET_DEVICES ; do
  33.                 DISABLED=0
  34.                 path=`readlink -f /sys/class/net/$DEVICE`
  35.         dev_path=""
  36.                 log "VERBOSE" "ethernet: $path"
  37.                 if ! [ -z $path ]; then
  38.                         if [ -d $path/device ]; then
  39.                           dev_path=`readlink -f $path/device`
  40.                           log "VERBOSE" "ethernet: $dev_path"
  41.                         fi
  42.                 fi
  43.  
  44.                 if ! [ -z $dev_path ] && [ -f $dev_path/enable ]; then
  45.                         if [ x$DISABLE_ETHERNET = x1 ]; then
  46.                                 if [ -f $dev_path/enable ]; then
  47.                                         echo 0 > $dev_path/enable
  48.                                         log "VERBOSE" "ethernet: Disabling ethernet device $DEVICE"
  49.                                         DISABLED=1
  50.                                 fi
  51.                         elif [ x$DISABLE_ETHERNET = x0 ]; then
  52.                                 if [ -f $dev_path/enable ]; then
  53.                                         echo 1 > $dev_path/enable
  54.                                         log "VERBOSE" "ethernet: Re-enabling ethernet device $DEVICE"
  55.                                         DISABLED=0
  56.                                 fi
  57.                         elif [ x$DISABLE_ETHERNET = x2 ]; then
  58.                                 DISABLED=0 # Be safe. :-)
  59.                         else
  60.                                 DISABLED=0 # Same here. Be safe. :-)
  61.                                            # For all other cases also, just disable it.
  62.                         fi
  63.                 else
  64.                         log "VERBOSE" "$DEVICE does not seem to be supporting enable/disable"
  65.                 fi
  66.  
  67.                if [ x$DISABLED = x1 ]; then
  68.                        continue
  69.                fi
  70.  
  71.         # Wakeup-on-LAN handling
  72.         if [ x$DISABLE_WAKEUP_ON_LAN = x1 ] ; then
  73.             ret=`ethtool -s $DEVICE wol d 2>&1`
  74.                         exit_status=$?;
  75.             log "VERBOSE" "$ret"
  76.             if [ $exit_status -eq 0 ]; then            
  77.                 log "VERBOSE" "Enabled wakeup-on-LAN for $DEVICE"
  78.             else
  79.                 log "VERBOSE" "Could not enable wakeup-on-LAN for $DEVICE"
  80.             fi
  81.         fi
  82.         
  83.         # Determine speed
  84.         speed=`mii-tool -v $DEVICE 2>/dev/null | grep capabilities | tr ' ' '\n' |\
  85.                         sort -n | sed -ne '/^1.*/p' | cut -d "b" -f1`
  86.                 if [ -z "$speed" ]; then
  87.                         speed=0;
  88.                 fi
  89.         max_s=0;
  90.         min_s=100000;
  91.         for s in $speed;
  92.         do
  93.             if [ $s -gt $max_s ]; then
  94.                 max_s=$s
  95.             fi
  96.             if [ $s -lt $min_s ]; then
  97.                 min_s=$s
  98.             fi
  99.         done
  100.         MAX_SPEED=$max_s;
  101.  
  102.         case "$THROTTLE_SPEED" in
  103.             "slowest")
  104.             THROTTLE_SPEED=$min_s
  105.             ;;
  106.             "fastest")
  107.             THROTTLE_SPEED=$max_s
  108.             ;;
  109.         esac
  110.  
  111.         # Handle throttling
  112.         if [ x$THROTTLE_ETHERNET = x1 ] ; then
  113.             # Handle auto-negotiation
  114.             ret=`ethtool -s $DEVICE autoneg off 2>&1`
  115.                         exit_status=$?;
  116.                         log "VERBOSE" "$ret";
  117.             if [ $exit_status -eq 0 ]; then
  118.                 log "VERBOSE" "Switched auto-negotiation to off for $DEVICE"
  119.             else
  120.                 log "VERBOSE" "Could not set auto-negotiation to off for $DEVICE"
  121.             fi
  122.  
  123.             # Handle Speed Throttling
  124.             ret=`ethtool -s $DEVICE speed $THROTTLE_SPEED 2>&1`
  125.                         exit_status=$?;
  126.                         log "VERBOSE" "$ret";
  127.             if [ $exit_status -eq 0 ]; then
  128.                 log "VERBOSE" "Throttled speed to $THROTTLE_SPEED Mbit for $DEVICE"
  129.             else
  130.                 log "VERBOSE" "Could not throttle speed for $DEVICE"
  131.             fi
  132.         else
  133.             # Handle auto-negotiation
  134.             ret=`ethtool -s $DEVICE autoneg on 2>&1`
  135.                         exit_status=$?;
  136.                         log "VERBOSE" "$ret";
  137.             if [ $exit_status -eq 0 ]; then
  138.                 log "VERBOSE" "Switched auto-negotiation to on for $DEVICE"
  139.             else
  140.                 log "VERBOSE" "Could not set auto-negotiation to on for $DEVICE"
  141.             fi
  142.  
  143.             # Handle Speed Throttling
  144.             ret=`ethtool -s $DEVICE speed $MAX_SPEED 2>&1`
  145.                         exit_status=$?;
  146.                         log "VERBOSE" "$ret";
  147.             if [ $exit_status -eq 0 ]; then
  148.                 log "VERBOSE" "Restored speed to $MAX_SPEED Mbit for $DEVICE"
  149.             else
  150.                 log "VERBOSE" "Could not restore speed for $DEVICE"
  151.             fi
  152.         fi
  153.     done
  154. else
  155.     log "VERBOSE" "Ethernet module is disabled."
  156. fi
  157.  
  158.