]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.phy
Add support for LEDs
[people/ms/network.git] / src / functions / functions.phy
index e80b1221528123fc84987e04537ce3f773435661..6ebfbb3012e383753c01a18abf7cf6b1b84fb6c1 100644 (file)
@@ -98,3 +98,50 @@ phy_get_devices() {
                fi
        done
 }
+
+phy_list_leds() {
+       local phy="${1}"
+
+       # Check if the PHY exists
+       assert phy_exists "${phy}"
+
+       local led
+       for led in $(list_directory /sys/class/leds); do
+               # Get basename of the LED
+               led=${led%*/}
+
+               if [[ ${led} =~ ${phy}(:.*)?$ ]]; then
+                       print "${led}"
+               fi
+       done
+}
+
+# This function tries to automatically configure LEDs to
+# something useful
+phy_leds_autoconf() {
+       local phy="${1}"
+       assert isset phy
+
+       local led
+       for led in $(phy_list_leds "${phy}"); do
+               # Skip some types of LEDs
+               case "${led}" in
+                       # Pretty much everything we tested from Ralink
+                       # locked up the kernel after a couple of seconds
+                       rt*)
+                               continue
+                               ;;
+               esac
+
+               # We try to set the LED into tpt mode (flashing on activity),
+               # but will fallback to tx mode if that isn't supported
+               local trigger
+               for trigger in "${phy}tpt" "${phy}tx"; do
+                       if led_set_trigger "${led}" "${trigger}"; then
+                               break
+                       fi
+               done
+       done
+
+       return ${EXIT_OK}
+}