I have a bunch of little 2.5" Western Digital "My Passport" USB disks, they're pretty useful and have proved to be very reliable so far. One thing I dislike about them is the status LED... It blinks when the disk is in power saving mode, and it's bright enough to be annoying in a dark room.
Western Digital actually provide WD Drive Utilities for Windows and Mac to control the LED (amongst other things), but so far I haven't found a tool for Linux. So it's time to fix that!
To find out what commands the WD util sends, I installed the official WD Drive Utilities on my Windows 10 laptop, along with Wireshark and USBPcap. USBPcap is a driver that captures USB traffic on a system and dumps it to a file that Wireshark can inspect. I started the USB capture and loaded WD Drive Utilities, and then toggled the LED mode a few times to generate the commands.
Once all the commands were captured it was just a simple case of finding out which parameters varied based on the LED state and figuring out how to send the commands from Linux APIs.
It turned out that the LED is controlled by the seventh byte in SCSI Mode Page 0x21, and sgutils2 is a good Library for sending SCSI Mode Page manipulation commands.
Here's my small little C program to control the LEDs easily from Linux: https://github.com/jbit/wdled/ (It probably works on other OS' with sgutils2 support too, let me know!)
It's intentionally paranoid about what devices it'll send commands to, read the README for more information!