[PATCH 1/3] WOL: Script to check status and to enable/disable Wake On LAN

Holger Macht hmacht at suse.de
Tue Aug 14 06:22:02 PDT 2007


Add script hal-system-wol to be installed as backend script below
/usr/lib/hal/scripts/linux/. Symbolic links in /usr/lib/hal/scripts define
which method is called:

 hal-system-wol-enable -> linux/hal-system-wol
 hal-system-enabled -> linux/hal-system-wol
 hal-system-enable -> linux/hal-system-wol

Script uses ethtool to determine and to set Wake On LAN capabilities:

 Check if WOL is supported: ethtool <iface>
 Enable/disable WOL: ethtool -s iface wol umbg

Signed-off-by: Holger Macht <hmacht at suse.de>
---

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 077e362..24dfe59 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -210,6 +210,12 @@ install-data-local:
 	-$(mkdir_p) $(DESTDIR)$(localstatedir)/lib/hal
 	-chown $(HAL_USER):$(HAL_GROUP) $(DESTDIR)$(localstatedir)/lib/hal
 	-chmod 0700 $(DESTDIR)$(localstatedir)/lib/hal
+	ln -sf $(DESTDIR)$(scriptdir)/linux/hal-system-wol $(DESTDIR)$(scriptdir)/hal-system-wol-enable
+	ln -sf $(DESTDIR)$(scriptdir)/linux/hal-system-wol $(DESTDIR)$(scriptdir)/hal-system-wol-enabled
+	ln -sf $(DESTDIR)$(scriptdir)/linux/hal-system-wol $(DESTDIR)$(scriptdir)/hal-system-wol-supported
+
+uninstall-local:
+	rm -f $(DESTDIR)$(scriptdir)/hal-system-wol-*
 
 clean-local :
 	rm -f *~
diff --git a/tools/linux/Makefile.am b/tools/linux/Makefile.am
index 689b068..4a0d2e8 100644
--- a/tools/linux/Makefile.am
+++ b/tools/linux/Makefile.am
@@ -37,7 +37,8 @@ script_SCRIPTS =					\
 	hal-system-lcd-set-brightness-linux		\
 	hal-system-power-set-power-save-linux		\
 	hal-system-killswitch-get-power-linux		\
-	hal-system-killswitch-set-power-linux
+	hal-system-killswitch-set-power-linux		\
+	hal-system-wol
 
 EXTRA_DIST = 90-hal.rules $(script_SCRIPTS)
 
diff --git a/tools/linux/hal-system-wol b/tools/linux/hal-system-wol
new file mode 100755
index 0000000..bbd8e5f
--- /dev/null
+++ b/tools/linux/hal-system-wol
@@ -0,0 +1,102 @@
+#!/bin/bash
+#
+# Copyright (C) 2007 Holger Macht <holger at homac.de>
+#
+# Author: Holger Macht <holger at homac.de>
+#
+# This file is released under the GPLv2.
+#
+
+SUPPORT_FLAGS=
+
+wol_supported() {
+    UDI=$1
+    
+    IFACE=`hal-get-property --udi $UDI --key net.interface`
+    if [ -z "$IFACE" ]; then
+	echo "org.freedesktop.Hal.Device.WakeOnLAN.NotSupported"
+	return 1
+    fi
+
+    SUPPORT_FLAGS=`ethtool $IFACE | grep "Supports Wake-on:" | awk '{ print $3 }' | grep g`
+    [ -n "$SUPPORT_FLAGS" ] && return 0
+    return 1
+}
+
+wol_enabled() {
+    UDI=$1
+
+    IFACE=`hal-get-property --udi $UDI --key net.interface`
+    if [ -z "$IFACE" ]; then
+	echo "org.freedesktop.Hal.Device.WakeOnLAN.NotSupported"
+	return 1
+    fi
+
+    ENABLED=`ethtool $IFACE | grep "[^s ]Wake-on:" | awk '{ print $2 }' | grep g`
+    [ -n "$ENABLED" ] && return 0
+    return 1
+}
+
+wol_enable() {
+    UDI=$1
+
+    IFACE=`hal-get-property --udi $UDI --key net.interface`
+    if [ -z "$IFACE" ]; then
+	echo "org.freedesktop.Hal.Device.WakeOnLAN.NotSupported"
+	return 1
+    fi
+
+    if [ -z "$SUPPORT_FLAGS" ]; then
+	echo "No support flags set, using default: g"
+	SUPPORT_FLAGS=g
+    fi
+
+    ethtool -s $IFACE wol $SUPPORT_FLAGS
+    if [ "$?" != "0" ]; then
+	echo "error enabling wake on LAN for interface $IFACE"
+	return 1
+    fi
+}
+
+wol_disable() {
+    UDI=$1
+
+    IFACE=`hal-get-property --udi $UDI --key net.interface`
+    ethtool -s $IFACE wol d
+    if [ "$?" != "0" ]; then
+	echo "error enabling wake on LAN for interface $IFACE"
+	return 1
+    fi
+}
+
+[ -z "$UDI" ] && exit 1
+
+which ethtool >/dev/null 2>&1
+if [ "$?" != "0" ]; then
+    echo "org.freedesktop.Hal.Device.WakeOnLan.NoEthtool"
+    exit 1
+fi
+
+case "`basename $0`" in
+    hal-system-wol-supported)
+	wol_supported $UDI
+	;;
+    hal-system-wol-enabled)
+	wol_enabled $UDI
+	;;
+    hal-system-wol-enable)
+	read enable
+	if [ "$enable" = "true" ]; then
+	    wol_enable $UDI
+	elif [ "$enable" = "false" ]; then
+	    wol_disable $UDI
+	else
+	    echo "org.freedesktop.Hal.Device.WakeOnLAN.InvalidArgument"
+	    exit 1
+	fi
+	;;
+    *) ;;
+	
+esac
+
+exit $?


More information about the hal mailing list