Adam Gensler wrote:
> Thanks for the reply, I appreciate the clarification.
>
> May I ask how you're turning the WAN LED to green in your setup? What
> mechanism do you use to do it? I've been unsuccesful thus far but perhaps I'm
> not trying the proper set of adjustments. More specifically can you share your
> /etc/config/network and also /etc/config/system?
I'm attaching three of my local patches that deal with the WAN LED:
netifd_dhcpc_hotplug.patch adds a hotplug action for any DHCP event. Upon
any DHCP event, scripts in /etc/hotplug.d/dhcpc will run with the "action"
environment variable set to "bound", "renew", "leasefail", "nak", or
"deconfig".
ifplugd_support.patch adds a new package, ifplugd_support, that sets up
ifplugd to watch the interface backing WAN, and ties it into a hotplug
action. Upon any ifplugd event, scripts in /etc/hotplug.d/ifplugd will run
with the IFPLUGD_INTERFACE environment variable set to the interface name
and the IFPLUGD_ACTION environment variable set to the argument to the
ifplugd.action script. I've seen this argument not be correct, so I
recommend using the IFPLUGD_CURRENT environment variable set by ifplugd in
preference to IFPLUGD_ACTION. Possible values are "down", "up", and
"error". This patch also includes a hotplug action to request DHCP lease
renewal on the WAN port when the cable is (re)connected. In order to use
this patch, you need to enable ifplugd in busybox
(CONFIG_BUSYBOX_CONFIG_IFPLUGD=y, Base system/busybox/Networking
Utilities/ifplugd) and also enable this package
(CONFIG_PACKAGE_ifplugd_support=y, Custom/ifplugd_support).
wndr3700_wan_led.patch contains hotplug actions for both ifplugd and
udhcpc. They both operate on the WAN interface only. The ifplugd action
will set the WAN LED to amber when the cable is disconnected. When the
cable is connected and the WAN interface is not being configured by DHCP,
the WAN LED is set to green if the link speed is gigabit (or faster?) or
amber if it's slower. The dhcpc action sets the WAN LED to green when a
DHCP lease is obtained or renewed, and amber for other DHCP events. This
patch also removes configuration of the WAN LED from /etc/config/system,
otherwise, /etc/rc.d/S96led would turn the LED amber, possibly after the
ifplugd or dhcpc actions set it properly. However, if you're sysupgrading
and preserving your existing configuration files, you'll need to remove
the "config led led_wan" section from /etc/config/system by hand, because
the uci-defaults script only sets the defaults, it doesn't modify existing
configurations.
It would probably be slicker if the link speed control could be handled
in-kernel by an LED trigger that tracks link speed. netifd polls the link
state and it isn't perfect, although it gets pretty close. I set it up
this way because I already had netifd set up to watch the WAN port to
trigger DHCP renewal. I probably wouldn't have gone to the trouble at all
just for LEDs otherwise. Similarly, I set up the dhcpc hotplug support for
another reason, and tying in the LED was simple at that point.
As mentioned, my /etc/config/system doesn't have a "config led led_wan"
section. The LED configuration in /etc/config/network is at the defaults:
port 1 = 6, port 2 = 9, and port 5 = 2.
Index: package/netifd/files/lib/netifd/dhcp.script
===================================================================
--- package/netifd/files/lib/netifd/dhcp.script (revision 33310)
+++ package/netifd/files/lib/netifd/dhcp.script (working copy)
@@ -47,13 +47,17 @@
proto_send_update "$INTERFACE"
}
-case "$1" in
- deconfig)
- deconfig_interface
- ;;
- renew|bound)
- setup_interface
- ;;
-esac
+(
+ case "$1" in
+ deconfig)
+ deconfig_interface
+ ;;
+ renew|bound)
+ setup_interface
+ ;;
+ esac
+)
+env "action=${1}" hotplug-call dhcpc
+
exit 0
Index: package/ifplugd_support/Makefile
===================================================================
--- package/ifplugd_support/Makefile (revision 0)
+++ package/ifplugd_support/Makefile (revision 0)
@@ -0,0 +1,54 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=ifplugd_support
+PKG_VERSION:=0.1
+PKG_RELEASE:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ifplugd_support
+ SECTION:=base
+ CATEGORY:=Custom
+ TITLE:=ifplugd support
+ MAINTAINER:=Mark Mentovai <m...@moxienet.com>
+ DEPENDS:=@BUSYBOX_CONFIG_IFPLUGD
+endef
+
+define Package/ifplugd_support/description
+ ifplugd support
+ Enables ifplugd to monitor the WAN interface, requesting DHCP lease renewal
+ upon cable reconnection, and allowing further extension via hotplug.
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/ifplugd_support/install
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) files/ifplugd $(1)/etc/init.d
+ $(INSTALL_DIR) $(1)/etc/ifplugd
+ $(INSTALL_BIN) files/ifplugd.action $(1)/etc/ifplugd
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/ifplugd
+ $(INSTALL_DATA) files/10-dhcp $(1)/etc/hotplug.d/ifplugd
+endef
+
+define Package/ifplugd_support/postinst
+if [[ -z "$${IPKG_INSTROOT}" ]]; then
+ /etc/init.d/ifplugd enable
+ /etc/init.d/ifplugd enable
+fi
+exit 0
+endef
+
+define Package/ifplugd_support/prerm
+if [[ -z "$${IPKG_INSTROOT}" ]]; then
+ /etc/init.d/ifplugd disable
+ /etc/init.d/ifplugd disable
+fi
+exit 0
+endef
+
+$(eval $(call BuildPackage,ifplugd_support))
Index: package/ifplugd_support/files/ifplugd
===================================================================
--- package/ifplugd_support/files/ifplugd (revision 0)
+++ package/ifplugd_support/files/ifplugd (revision 0)
@@ -0,0 +1,24 @@
+#!/bin/sh /etc/rc.common
+
+START=90
+STOP=10
+
+. /lib/functions/network.sh
+
+OBSERVE_INTERFACE=wan
+
+observe_device() {
+ local device
+ network_get_device device "${OBSERVE_INTERFACE}"
+ echo "${device}"
+}
+
+start() {
+ local device="$(observe_device)"
+ ifplugd -i "${device}" -a -I
+}
+
+stop() {
+ local device="$(observe_device)"
+ ifplugd -i "${device}" -k
+}
Property changes on: package/ifplugd_support/files/ifplugd
___________________________________________________________________
Added: svn:executable
+ *
Index: package/ifplugd_support/files/10-dhcp
===================================================================
--- package/ifplugd_support/files/10-dhcp (revision 0)
+++ package/ifplugd_support/files/10-dhcp (revision 0)
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# Request DHCP renewal when a cable is connected to the WAN port.
+
+. /lib/functions.sh
+. /lib/functions/network.sh
+
+OBSERVE_INTERFACE="wan"
+
+observe_device() {
+ local device
+ network_get_device device "${OBSERVE_INTERFACE}"
+ echo "${device}"
+}
+
+main() {
+ local device="$(observe_device)"
+
+ if [[ "${IFPLUGD_INTERFACE}" != "${device}" ]]; then
+ return 0
+ fi
+
+ config_load network
+ local proto
+ config_get proto "${OBSERVE_INTERFACE}" proto
+
+ case "${proto}" in
+ dhcp)
+ if [[ "${IFPLUGD_CURRENT}" = "up" ]] &&
+ [[ "${IFPLUGD_PREVIOUS}" = "down" ]]; then
+ local pid_file="/var/run/udhcpc-${IFPLUGD_INTERFACE}.pid"
+ local pid="$(cat "${pid_file}")"
+ kill -USR1 "${pid}"
+ fi
+ ;;
+ *)
+ ;;
+ esac
+}
+
+main "${@}"
Index: package/ifplugd_support/files/ifplugd.action
===================================================================
--- package/ifplugd_support/files/ifplugd.action (revision 0)
+++ package/ifplugd_support/files/ifplugd.action (revision 0)
@@ -0,0 +1,2 @@
+#!/bin/sh
+env "IFPLUGD_INTERFACE=${1}" "IFPLUGD_ACTION=${2}" hotplug-call ifplugd
Property changes on: package/ifplugd_support/files/ifplugd.action
___________________________________________________________________
Added: svn:executable
+ *
Index: target/linux/ar71xx/base-files/etc/hotplug.d/ifplugd/05-ifplugd_wan_led
===================================================================
--- target/linux/ar71xx/base-files/etc/hotplug.d/ifplugd/05-ifplugd_wan_led
(revision 0)
+++ target/linux/ar71xx/base-files/etc/hotplug.d/ifplugd/05-ifplugd_wan_led
(revision 0)
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+# The color of the WNDR3700 WAN LED is controlled by software. Unlike the LAN
+# switch port LEDs, the hardware cannot tie the color of the WAN LED to the
+# link speed.
+#
+# The stock firmware turns the WAN LED green when an Internet connection is
+# present. That feature is accommodated in
+# /etc/hotplug.d/dhcpc/05-dhcpc_wan_led when DHCP is in use for the WAN port.
+# For protocols other than DHCP, set the color based on the link speed at the
+# time the link is established. The LED color will not change if the link
+# speed changes after the link is up.
+#
+# Activation of the LED is controlled by the LED settings for switch port 5
+# in /etc/config/network. Software control (this script) can only alter the
+# LED color, not its on/off state which is directed by hardware. The color
+# choices are green and amber.
+
+. /lib/functions.sh
+. /lib/functions/network.sh
+
+OBSERVE_INTERFACE="wan"
+BRIGHTNESS_FILE="/sys/class/leds/wndr3700:green:${OBSERVE_INTERFACE}/brightness"
+COLOR_GREEN="255"
+COLOR_AMBER="0"
+
+observe_device() {
+ local device
+ network_get_device device "${OBSERVE_INTERFACE}"
+ echo "${device}"
+}
+
+main() {
+ local device="$(observe_device)"
+
+ if [[ "${IFPLUGD_INTERFACE}" != "${device}" ]] ||
+ ! [[ -e "${BRIGHTNESS_FILE}" ]]; then
+ return 0
+ fi
+
+ config_load network
+ local proto
+ config_get proto "${OBSERVE_INTERFACE}" proto
+
+ local brightness_value
+ case "${IFPLUGD_CURRENT}" in
+ up)
+ case "${proto}" in
+ dhcp)
+ # The LED color is set based on DHCP state and not interface speed.
+ # See /etc/hotplug.d/dhcpc/05-led.
+ ;;
+ *)
+ local device
+ network_get_device device "${INTERFACE}"
+ local speed
+ speed=$(cat "/sys/class/net/${IFPLUGD_INTERFACE}/speed")
+
+ # Don't use |else|. If ${speed} is not a number, both of these
+ # conditions will be false.
+ if [[ "${speed}" -ge 1000 ]] 2>/dev/null; then
+ brightness_value="${COLOR_GREEN}"
+ fi
+ if [[ "${speed}" -lt 1000 ]] 2>/dev/null; then
+ brightness_value="${COLOR_AMBER}"
+ fi
+ ;;
+ esac
+ ;;
+ *)
+ # When unplugged, the LED should be set to amber even when DHCP is in
+ # use. /etc/hotplug.d/ifplugd/10-dhcp will attempt to renew the lease
+ # when the interface is reconnected, which will turn the LED green again
+ # upon successful renewal or rebind.
+ brightness_value="${COLOR_AMBER}"
+ ;;
+ esac
+
+ if [[ -n "${brightness_value}" ]]; then
+ echo "${brightness_value}" > "${BRIGHTNESS_FILE}"
+ fi
+}
+
+main "${@}"
Index: target/linux/ar71xx/base-files/etc/hotplug.d/dhcpc/05-dhcpc_wan_led
===================================================================
--- target/linux/ar71xx/base-files/etc/hotplug.d/dhcpc/05-dhcpc_wan_led
(revision 0)
+++ target/linux/ar71xx/base-files/etc/hotplug.d/dhcpc/05-dhcpc_wan_led
(revision 0)
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+# The stock firmware turns the WAN LED green when an Internet connection is
+# present. Mimic that feature by setting it to green when a DHCP lease is
+# obtained, if DHCP is in use for the WAN port. Protocols other than DHCP are
+# accommodated in /etc/hotplug.d/ifplugd/05-dhcpc_wan_led.
+#
+# Activation of the LED is controlled by the LED settings for switch port 5
+# in /etc/config/network. Software control (this script) can only alter the
+# LED color, not its on/off state which is directed by hardware. The color
+# choices are green and amber.
+
+. /lib/functions/network.sh
+
+OBSERVE_INTERFACE="wan"
+BRIGHTNESS_FILE="/sys/class/leds/wndr3700:green:${OBSERVE_INTERFACE}/brightness"
+COLOR_GREEN="255"
+COLOR_AMBER="0"
+
+observe_device() {
+ local device
+ network_get_device device "${OBSERVE_INTERFACE}"
+ echo "${device}"
+}
+
+main() {
+ local device="$(observe_device)"
+
+ if [[ "${interface}" != "${device}" ]] ||
+ ! [[ -e "${BRIGHTNESS_FILE}" ]]; then
+ return 0
+ fi
+
+ local brightness_value
+ case "${action}" in
+ bound|renew)
+ brightness_value="${COLOR_GREEN}"
+ ;;
+ *)
+ brightness_value="${COLOR_AMBER}"
+ ;;
+ esac
+
+ if [[ -n "${brightness_value}" ]]; then
+ echo "${brightness_value}" > "${BRIGHTNESS_FILE}"
+ fi
+}
+
+main "${@}"
Index: target/linux/ar71xx/base-files/etc/uci-defaults/leds
===================================================================
--- target/linux/ar71xx/base-files/etc/uci-defaults/leds (revision 33504)
+++ target/linux/ar71xx/base-files/etc/uci-defaults/leds (working copy)
@@ -154,7 +154,7 @@
;;
wndr3700)
- ucidef_set_led_default "wan" "WAN LED (green)" "wndr3700:green:wan" "0"
+# ucidef_set_led_default "wan" "WAN LED (green)" "wndr3700:green:wan" "0"
ucidef_set_led_usbdev "usb" "USB" "wndr3700:green:usb" "1-1"
;;
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel