[PATCH 1/3] WOL: Script to check status and to enable/disable Wake On LAN
Holger Macht
hmacht at suse.de
Mon Oct 15 12:05:09 PDT 2007
On Tue 28. Aug - 14:21:42, David Zeuthen wrote:
>
> On Tue, 2007-08-14 at 15:22 +0200, Holger Macht wrote:
> > +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
>
> Actually I think IFACE is the same as HAL_PROP_NET_INTERFACE; saves a
> fork + some IPC. Ditto for getting other properties too.
>
> Btw, there should probably exist tools/hal-system-wol-* that looks sorta
> like this (this is snipped from another script in tools/) to check
> whether the caller is actually privileged to do this
>
> #!/bin/sh
> . hal-functions
>
> hal_check_priv org.freedesktop.hal.wol.<the-action>
> hal_exec_backend
>
> and you should define these PolicyKit actions in policy/hal-wol.policy
Added PolicyKit support and included suggestions from Dan Nicholson.
This time, everything is included in one single patch.
---
diff --git a/doc/spec/hal-spec-interfaces.xml b/doc/spec/hal-spec-interfaces.xml
index 4e5050f..ab1308b 100644
--- a/doc/spec/hal-spec-interfaces.xml
+++ b/doc/spec/hal-spec-interfaces.xml
@@ -878,6 +878,61 @@ $ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
</para>
</sect1>
+ <sect1 id="interface-wakeonlan">
+ <title>org.freedesktop.Hal.Device.WakeOnLan interface</title>
+ <para>
+ This interface provides a mechanism to configure Wake On LAN
+ capabilities. The following methods are available:
+ </para>
+
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Method</entry>
+ <entry>Returns</entry>
+ <entry>Parameters</entry>
+ <entry>Throws</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>GetSupported</entry>
+ <entry>Bool</entry>
+ <entry></entry>
+ <entry>WakeOnLan.NoEthtool</entry>
+ <entry>
+ Get if device supports Wake On LAN
+ </entry>
+ </row>
+ <row>
+ <entry>GetEnabled</entry>
+ <entry>Bool</entry>
+ <entry></entry>
+ <entry>WakeOnLan.NoEthtool</entry>
+ <entry>
+ Get if Wake On LAN is enabled
+ </entry>
+ </row>
+ <row>
+ <entry>SetEnabled</entry>
+ <entry>Void</entry>
+ <entry>Bool</entry>
+ <entry>WakeOnLan.NoEthtool</entry>
+ <entry>
+ Enable or disable Wake On LAN
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+
+ <para>
+ This interface does not emit any signals.
+ </para>
+ </sect1>
+
<sect1 id="interface-device-laptop-panel">
<title>org.freedesktop.Hal.Device.LaptopPanel interface</title>
<para>
diff --git a/fdi/policy/10osvendor/30-wol.fdi b/fdi/policy/10osvendor/30-wol.fdi
new file mode 100644
index 0000000..a668968
--- /dev/null
+++ b/fdi/policy/10osvendor/30-wol.fdi
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deviceinfo version="0.2">
+
+ <device>
+ <match key="info.capabilities" contains="net.80203">
+ <append key="info.capabilities" type="strlist">wake_on_lan</append>
+ <append key="info.interfaces" type="strlist">org.freedesktop.Hal.Device.WakeOnLan</append>
+
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_names" type="strlist">GetSupported</append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_signatures" type="strlist"></append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_argnames" type="strlist"></append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_execpaths" type="strlist">hal-system-wol-supported</append>
+
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_names" type="strlist">GetEnabled</append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_signatures" type="strlist"></append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_argnames" type="strlist"></append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_execpaths" type="strlist">hal-system-wol-enabled</append>
+
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_names" type="strlist">SetEnabled</append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_signatures" type="strlist">b</append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_argnames" type="strlist">enable</append>
+ <append key="org.freedesktop.Hal.Device.WakeOnLan.method_execpaths" type="strlist">hal-system-wol-enable</append>
+
+ </match>
+
+ </device>
+</deviceinfo>
diff --git a/fdi/policy/10osvendor/Makefile.am b/fdi/policy/10osvendor/Makefile.am
index 91b935e..5c05347 100644
--- a/fdi/policy/10osvendor/Makefile.am
+++ b/fdi/policy/10osvendor/Makefile.am
@@ -8,7 +8,8 @@ dist_fdi_DATA = \
10-rfkill-switch.fdi \
10-laptop-panel-mgmt-policy.fdi \
15-storage-luks.fdi \
- 20-storage-methods.fdi
+ 20-storage-methods.fdi \
+ 30-wol.fdi
if BUILD_KEYMAPS
dist_fdi_DATA += 10-keymap.fdi
diff --git a/policy/Makefile.am b/policy/Makefile.am
index a75808a..f3bcee6 100644
--- a/policy/Makefile.am
+++ b/policy/Makefile.am
@@ -6,7 +6,8 @@ dist_polkit_policy_DATA = \
hal-lock.policy \
hal-storage.policy \
hal-power.policy \
- hal-killswitch.policy
+ hal-killswitch.policy \
+ hal-wol.policy
if HAVE_ACLMGMT
dist_polkit_policy_DATA += hal-device-file.policy
diff --git a/policy/hal-wol.policy b/policy/hal-wol.policy
new file mode 100644
index 0000000..e9fbd47
--- /dev/null
+++ b/policy/hal-wol.policy
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+
+<policyconfig>
+
+ <action id="org.freedesktop.hal.wol.enabled">
+ <description>If Wake on LAN is enabled</description>
+ <message>System policy prevents checking if Wake on LAN is enabled</message>
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.freedesktop.hal.wol.enable">
+ <description>Enable or disable Wake on LAN</description>
+ <message>System policy prevents enabling or disabling Wake on LAN</message>
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.freedesktop.hal.wol.supported">
+ <description>If Wake on LAN is supported</description>
+ <message>System policy prevents checking if Wake on LAN is supported</message>
+ <defaults>
+ <allow_inactive>no</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+</policyconfig>
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 077e362..d153ac3 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -167,6 +167,9 @@ script_SCRIPTS = \
hal-system-power-set-power-save \
hal-system-killswitch-get-power \
hal-system-killswitch-set-power \
+ hal-system-wol-supported \
+ hal-system-wol-enabled \
+ hal-system-wol-enable \
hal-functions
EXTRA_DIST=$(man_MANS) $(MAN_IN_FILES) gen-libgphoto-hal-fdi $(script_SCRIPTS)
diff --git a/tools/hal-disable-polling.c b/tools/hal-disable-polling.c
diff --git a/tools/hal-setup-keymap-hash-name.h b/tools/hal-setup-keymap-hash-name.h
diff --git a/tools/hal-system-wol-enable b/tools/hal-system-wol-enable
new file mode 100644
index 0000000..b4de461
--- /dev/null
+++ b/tools/hal-system-wol-enable
@@ -0,0 +1,24 @@
+#!/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.
+#
+
+. hal-functions
+
+if [ -z "$UDI" -o -z "$HAL_PROP_NET_INTERFACE" ]; then
+ echo "org.freedesktop.Hal.Device.WakeOnLAN.UnknownError" >&2
+ echo "Missing or empty environment variable(s)." >&2
+ echo "This script should be started by hald." >&2
+ exit 1
+fi
+
+# read value for setting enabled or disabled
+read enable
+export enable
+
+hal_check_priv org.freedesktop.hal.wol.enable
+hal_exec_backend
diff --git a/tools/hal-system-wol-enabled b/tools/hal-system-wol-enabled
new file mode 100644
index 0000000..4901bc2
--- /dev/null
+++ b/tools/hal-system-wol-enabled
@@ -0,0 +1,20 @@
+#!/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.
+#
+
+. hal-functions
+
+if [ -z "$UDI" -o -z "$HAL_PROP_NET_INTERFACE" ]; then
+ echo "org.freedesktop.Hal.Device.WakeOnLAN.UnknownError" >&2
+ echo "Missing or empty environment variable(s)." >&2
+ echo "This script should be started by hald." >&2
+ exit 1
+fi
+
+hal_check_priv org.freedesktop.hal.wol.enabled
+hal_exec_backend
diff --git a/tools/hal-system-wol-supported b/tools/hal-system-wol-supported
new file mode 100644
index 0000000..4879c3b
--- /dev/null
+++ b/tools/hal-system-wol-supported
@@ -0,0 +1,20 @@
+#!/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.
+#
+
+. hal-functions
+
+if [ -z "$UDI" -o -z "$HAL_PROP_NET_INTERFACE" ]; then
+ echo "org.freedesktop.Hal.Device.WakeOnLAN.UnknownError" >&2
+ echo "Missing or empty environment variable(s)." >&2
+ echo "This script should be started by hald." >&2
+ exit 1
+fi
+
+hal_check_priv org.freedesktop.hal.wol.supported
+hal_exec_backend
diff --git a/tools/linux/Makefile.am b/tools/linux/Makefile.am
index 689b068..0aca29e 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-linux
EXTRA_DIST = 90-hal.rules $(script_SCRIPTS)
@@ -58,3 +59,11 @@ check:
clean-local :
rm -f *~
+
+install-data-local:
+ ln -sf $(DESTDIR)$(scriptdir)/hal-system-wol-linux $(DESTDIR)$(scriptdir)/hal-system-wol-enable-linux
+ ln -sf $(DESTDIR)$(scriptdir)/hal-system-wol-linux $(DESTDIR)$(scriptdir)/hal-system-wol-enabled-linux
+ ln -sf $(DESTDIR)$(scriptdir)/hal-system-wol-linux $(DESTDIR)$(scriptdir)/hal-system-wol-supported-linux
+
+uninstall-local:
+ rm -f $(DESTDIR)$(scriptdir)/hal-system-wol-*
diff --git a/tools/linux/hal-system-wol-linux b/tools/linux/hal-system-wol-linux
new file mode 100644
index 0000000..36909c3
--- /dev/null
+++ b/tools/linux/hal-system-wol-linux
@@ -0,0 +1,81 @@
+#!/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=
+IFACE="$HAL_PROP_NET_INTERFACE"
+
+wol_get_flags() {
+ SUPPORT_FLAGS=`ethtool $IFACE | awk '/Supports Wake-on:/{if ($3 ~ /g/) print $3 }'`
+ [ -n "$SUPPORT_FLAGS" ] && return 0
+ echo "org.freedesktop.Hal.Device.WakeOnLAN.NotSupported"
+ exit 1
+}
+
+wol_supported() {
+ wol_get_flags
+ [ -n "$SUPPORT_FLAGS" ] && return 0
+ return 1
+}
+
+wol_enabled() {
+ ENABLED=`ethtool $IFACE | awk '/[^s ]Wake-on:/{if ($2 ~ /g/) print $2 }'`
+ [ -n "$ENABLED" ] && return 0
+ return 1
+}
+
+wol_enable() {
+ wol_get_flags
+
+ 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() {
+ ethtool -s $IFACE wol d
+ if [ "$?" != "0" ]; then
+ echo "error disabling wake on LAN for interface $IFACE"
+ return 1
+ fi
+}
+
+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-linux)
+ wol_supported
+ ;;
+ hal-system-wol-enabled-linux)
+ wol_enabled
+ ;;
+ hal-system-wol-enable-linux)
+ if [ "$enable" = "true" ]; then
+ wol_enable
+ elif [ "$enable" = "false" ]; then
+ wol_disable
+ else
+ echo "org.freedesktop.Hal.Device.WakeOnLAN.InvalidArgument"
+ exit 1
+ fi
+ ;;
+ *) ;;
+esac
+
+exit $?
More information about the hal
mailing list