base-files: make it possible to specify switch led mode
authorChristian Lamparter <chunkeey@gmail.com>
Fri, 21 Sep 2018 22:38:40 +0000 (00:38 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 29 Sep 2018 15:23:11 +0000 (17:23 +0200)
The swconfig switch led driver has the ability to switch
between a "link, rx and/or tx" mode. However, this feature
was not implemented in uci, the led init script and
config_generate.

This patch adds a seventh parameter to the
ucidef_set_led_switch() function. The accepted values for
this parameter are: link, rx and tx.
Any permutations of these three values are supported, as
long as they are properly encased with quotes.
If the parameter is not specified it will default to "all"
(link rx tx).

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
package/base-files/files/bin/config_generate
package/base-files/files/etc/init.d/led
package/base-files/files/lib/functions/uci-defaults.sh

index c8b253da5bd2ccd06c0f3f6047b196394f918e03..df221cc26ca478a3923bf2299b7b2d26ae75119f 100755 (executable)
@@ -366,11 +366,12 @@ generate_led() {
                ;;
 
                switch)
-                       local port_mask speed_mask
-                       json_get_vars port_mask speed_mask
+                       local port_mask speed_mask mode
+                       json_get_vars port_mask speed_mask mode
                        uci -q batch <<-EOF
                                set system.$cfg.port_mask='$port_mask'
                                set system.$cfg.speed_mask='$speed_mask'
+                               set system.$cfg.mode='$mode'
                        EOF
                ;;
 
index c790e3e181f5c9dffeedfb0b267e64412b782142..a3f1224a1af13cd47ca6827244ffb3289dd86281 100755 (executable)
@@ -20,7 +20,7 @@ load_led() {
        config_get trigger $1 trigger "none"
        config_get dev $1 dev
        config_get ports $1 port
-       config_get mode $1 mode "link"
+       config_get mode $1 mode
        config_get_bool default $1 default "nil"
        config_get delayon $1 delayon
        config_get delayoff $1 delayoff
@@ -71,7 +71,7 @@ load_led() {
                "netdev")
                        [ -n "$dev" ] && {
                                echo $dev > /sys/class/leds/${sysfs}/device_name
-                               echo $mode > /sys/class/leds/${sysfs}/mode
+                               echo "${mode:-link}" > /sys/class/leds/${sysfs}/mode
                                echo $interval > /sys/class/leds/${sysfs}/interval
                        }
                        ;;
@@ -110,6 +110,8 @@ load_led() {
                        config_get speed_mask $1 speed_mask
                        [ -n "$speed_mask" ] && \
                                echo $speed_mask > /sys/class/leds/${sysfs}/speed_mask
+                       [ -n "$mode" ] && \
+                               echo "$mode" > /sys/class/leds/${sysfs}/mode
                        ;;
                esac
        }
index 7fa328ac20aaf82fb92a9fde131c6c70c681e92c..315df7b70821f5ce2a4feacbdf43564add957f29 100755 (executable)
@@ -442,11 +442,13 @@ ucidef_set_led_switch() {
        local trigger_name="$4"
        local port_mask="$5"
        local speed_mask="$6"
+       local mode="$7"
 
        _ucidef_set_led_common "$1" "$2" "$3"
 
        json_add_string trigger "$trigger_name"
        json_add_string type switch
+       json_add_string mode "$mode"
        json_add_string port_mask "$port_mask"
        json_add_string speed_mask "$speed_mask"
        json_select ..