mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2026-02-10 22:03:07 +01:00
73 lines
2 KiB
Text
73 lines
2 KiB
Text
include /lib/network
|
|
|
|
# true if speed on interface is Gbit
|
|
gigatest() {
|
|
local speed=$(ethctl $INTERFACE media-type 2>&1 | awk '{if (NR == 2) print $6}')
|
|
case "$speed" in
|
|
1000*) return 0 ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
# true if there is a link on any lan port
|
|
lan_test () {
|
|
local ledontest
|
|
for dev in $(db get hw.board.ethernetLanPorts); do
|
|
ledontest=$(cat /sys/class/net/$dev/operstate)
|
|
if [ "$ledontest" == "up" ]; then
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
case "$ACTION" in
|
|
add|register)
|
|
INTFNAME=$(interfacename $INTERFACE)
|
|
OPERSTATE=$(cat /sys/class/net/$INTERFACE/operstate)
|
|
# if [ "$OPERSTATE" == "up" ]; then
|
|
if true ; then
|
|
case "$INTFNAME" in
|
|
GbE*)
|
|
ubus call led.lan set '{"state" : "ok"}'
|
|
ubus call led.gbe set '{"state" : "ok"}'
|
|
ubus call led.gbe_phy_link set '{"state" : "ok"}'
|
|
ubus call led.gbe_phy_speed set '{"state": "off"}'
|
|
$(gigatest) && ubus call led.gbe_phy_speed set '{"state":"ok"}'
|
|
;;
|
|
LAN*)
|
|
ubus call led.lan set '{"state":"ok"}'
|
|
;;
|
|
WAN*)
|
|
ubus call led.wan set '{"state" : "ok"}'
|
|
ubus call led.wan_phy_link set '{"state" : "ok"}'
|
|
ubus call led.wan_phy_speed set '{"state" : "off"}'
|
|
$(gigatest) && ubus call led.wan_phy_speed set '{"state":"ok"}'
|
|
;;
|
|
esac
|
|
fi
|
|
;;
|
|
remove|unregister)
|
|
INTFNAME=$(interfacename $INTERFACE)
|
|
OPERSTATE=$(cat /sys/class/net/$INTERFACE/operstate)
|
|
if [ "$OPERSTATE" == "down" ]; then
|
|
case "$INTFNAME" in
|
|
GbE*)
|
|
ubus call led.gbe set '{"state" : "off"}'
|
|
ubus call led.gbe_phy_link set '{"state" : "off"}'
|
|
ubus call led.gbe_phy_speed set '{"state" : "off"}'
|
|
$(lan_test) || ubus call led.lan set '{"state":"off"}'
|
|
;;
|
|
LAN*)
|
|
$(lan_test) || ubus call led.lan set '{"state":"off"}'
|
|
;;
|
|
WAN*)
|
|
ubus call led.wan set '{"state" : "off"}'
|
|
ubus call led.wan_phy_speed set '{"state" : "off"}'
|
|
ubus call led.wan_phy_link set '{"state" : "off"}'
|
|
;;
|
|
esac
|
|
fi
|
|
;;
|
|
esac
|
|
|