home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / acpi-support / state-funcs < prev    next >
Encoding:
Text File  |  2007-03-29  |  2.1 KB  |  74 lines

  1. #!/bin/sh
  2. # Paul Sladen, 2006-03-28, 2007-03-26
  3. # Library functions to check/change status of wireless
  4.  
  5. # Return 0 if there is, allowing you to write   if isAnyWirelessPoweredOn; then ...
  6. isAnyWirelessPoweredOn()
  7. {
  8.     for DEVICE in /sys/class/net/* ; do
  9.     if [ -d $DEVICE/wireless -a -r $DEVICE/device/power/state ] ; then
  10.         # If any of the wireless devices are turned on then return success
  11.         if [ "`cat $DEVICE/device/power/state`" -eq 0 ] ; then
  12.         # Check if 'rf_kill' disagrees
  13.         if [ -r $DEVICE/device/rf_kill ] ; then
  14.             if [ "`cat $DEVICE/device/rf_kill`" -eq 0 ] ; then
  15.             # And rf_kill has the radio on
  16.             return 0
  17.             fi
  18.         else
  19.             return 0
  20.         fi
  21.         fi
  22.     fi
  23.     done
  24.     # otherwise return failure
  25.     return 1
  26. }
  27.  
  28. # Takes no parameters, toggles all wireless devices.
  29. # TODO: Should possible toggle all wireless devices to the state of the first one.
  30. # Attempts to use 'rf_kill' first, and then tries 'power/state', though that
  31. # will fail on >=2.6.18 kernels since upstream removed the functionality...
  32. toggleAllWirelessStates()
  33. {
  34.     for DEVICE in /sys/class/net/* ; do
  35.     if [ -d $DEVICE/wireless ] ; then
  36.         # $DEVICE is a wireless device. Check if it's powered on:
  37.         ON=0
  38.         OFF=1  # 1 for rf_kill, 2 for power/state
  39.         for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do
  40.         if [ -w $CONTROL ] ; then
  41.             # We have a way of controlling the device, lets try
  42.             if [ "`cat $CONTROL`" = 0 ] ; then
  43.             # It's powered on. Switch it off.
  44.             if echo -n $OFF > $CONTROL ; then 
  45.                 break
  46.             else
  47.                 OFF=2 # for power/state, second time around
  48.             fi
  49.             else
  50.             # It's powered off. Switch it on.
  51.             if echo -n $ON > $CONTROL ; then
  52.                 break
  53.             fi
  54.             fi
  55.         fi
  56.         done
  57.     fi
  58.     done
  59. }
  60.  
  61. # Pass '1' to blink suspending LED and '0' to stop LED
  62. setLEDThinkpadSuspending()
  63. {
  64.     action=`test "$1" -ne 0 && echo blink || echo off`
  65.     test -w /proc/acpi/ibm/led && echo -n 7 "$action" > /proc/acpi/ibm/led
  66. }
  67.  
  68. # Pass '1' to light LED and '0' to dark LED
  69. setLEDAsusWireless()
  70. {
  71.     action=`test "$1" -ne 0 && echo 1 || echo 0`
  72.     test -w /proc/acpi/asus/wled && echo -n "$action" > /proc/acpi/asus/wled
  73. }
  74.