src/functions/functions.ip-tunnel \
src/functions/functions.ipv4 \
src/functions/functions.ipv6 \
+ src/functions/functions.leds \
src/functions/functions.list \
src/functions/functions.lock \
src/functions/functions.logging \
--- /dev/null
+#!/bin/bash
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2018 IPFire Network Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+led_exists() {
+ local led="${1}"
+ assert isset led
+
+ file_exists "/sys/class/leds/${led}"
+}
+
+led_get_supported_triggers() {
+ local led="${1}"
+
+ if ! led_exists "${led}"; then
+ error "LED ${led} does not exist"
+ return ${EXIT_ERROR}
+ fi
+
+ local triggers="$(fread "/sys/class/leds/${led}/trigger")"
+
+ # Filter markers for active trigger
+ print "${triggers//[\[\]]/}"
+}
+
+led_set_trigger() {
+ local led="${1}"
+ local trigger="${2}"
+
+ assert isset led
+ assert isset trigger
+
+ local supported_triggers="$(led_get_supported_triggers "${led}")"
+ if ! list_match "${trigger}" ${supported_triggers}; then
+ log DEBUG "Trigger ${trigger} is not supported by LED ${led}"
+ return ${EXIT_ERROR}
+ fi
+
+ log DEBUG "Setting LED trigger ${trigger} for ${led}"
+ fwrite "/sys/class/leds/${led}/trigger" "${trigger}"
+}
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}
+}