Showing posts with label turn off wifi led. Show all posts
Showing posts with label turn off wifi led. Show all posts

Monday, June 22, 2009

Stop the WiFi Keyboard LED from Flashing

When I first installed Ubuntu on my Vostro 1500, I was very happy that the wireless card worked. Ordering the correct hardware is one thing, actually printing "Hello World" is another.

Two days later I was cursing the wireless worked. The wireless LED that is. It's a constant bright blue blinking light that's extremely annoying. After googling, I finally discovered that I could control it via the /sys file system:

# echo iphy0assoc > '/sys/class/leds/iwl-phy0:assoc/trigger'
# echo none > '/sys/class/leds/iwl-phy0:radio/trigger'
# echo none > '/sys/class/leds/iwl-phy0:RX/trigger'
# echo none > '/sys/class/leds/iwl-phy0:TX/trigger

Woot! The light turned off. For two seconds. Then was back again. Still bright, still blue, still blinking, still annoying. It took me a couple nights, but then I woke up. Haduh! Computers do the redundant really well! So I wrote a simple C program:

#include <unistd.h>

int main ( ) {
 while ( 1 ) {
  // loop endlessly

  system( "echo iphy0assoc > '/sys/class/leds/iwl-phy0:assoc/trigger'" );
  system( "echo none > '/sys/class/leds/iwl-phy0:radio/trigger'" );
  system( "echo none > '/sys/class/leds/iwl-phy0:RX/trigger'" );
  system( "echo none > '/sys/class/leds/iwl-phy0:TX/trigger'" );

  system( "echo 0 > '/sys/class/leds/iwl-phy0:radio/brightness'" );
  sleep( 2 ); // wait 2 seconds, before doing it again
 }
}

Basically, an endless loop, turning off the wifi led every 2 seconds. Compilation was easy:

$ gcc -Os -o turn_off_wifi_led turn_off_wifi_led.c

Now, the tricky part is that this must be run as root, and I don't want to have to run it manually every time I login. Luckily, our Unix engineers have thought of this: setuid

$ ll turn_off_wifi_led
-rwxr-xr-x 1 kevin kevin 6.3K 2009-06-22 01:59 turn_off_wifi_led

$ sudo chown root:kevin turn_off_wifi_led
$ sudo chmod 4755 turn_off_wifi_led
-rwsr-xr-x 1 root kevin 6.3K 2009-06-22 01:59 turn_off_wifi_led

Now, because it's setuid, and it's owned by root, no matter who executes the turn_off_wifi_led program, it will run with root privileges.

The last actions are to put it my bin folder, and to run it automatically when I log in:

$ mv turn_off_wifi_led ~/bin

Then go to System→Preferences→Startup Applications. Click 'Add' to make a new entry in the table:

Name:    Kill WiFi LED
Command: /home/kevin/bin/turn_off_wifi_led &
Comment: Turn off that damned annoying, always flashing, blue wifi LED.

Click Save, then Close. VoilĂ ! After logging back in, the annoying blue LED is off for good!