hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Wed Aug 20 11:24:03 PDT 2008
fdi/policy/10osvendor/10-rfkill-switch.fdi | 27 +
hald/linux/addons/Makefile.am | 4
hald/linux/addons/addon-ipw-killswitch.c | 305 ++++++++++++++++++++++
tools/linux/Makefile.am | 7
tools/linux/hal-ipw-killswitch-linux.c | 158 -----------
tools/linux/hal-system-killswitch-get-power-linux | 12
tools/linux/hal-system-killswitch-set-power-linux | 13
7 files changed, 328 insertions(+), 198 deletions(-)
New commits:
commit 5edd46d2ef3bd0c702c149473a3e444aab6658a0
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Wed Aug 20 20:23:28 2008 +0200
added new addon for the ipw killswitch interface
Added new addon to set/get values to/from the ipw (intel) WLAN killswitch
interface to improve the performance while get/set the killswitch state
by preventing fork three times for each change or status request in the
current script-code.
diff --git a/fdi/policy/10osvendor/10-rfkill-switch.fdi b/fdi/policy/10osvendor/10-rfkill-switch.fdi
index c6b8a72..7977dcc 100644
--- a/fdi/policy/10osvendor/10-rfkill-switch.fdi
+++ b/fdi/policy/10osvendor/10-rfkill-switch.fdi
@@ -4,17 +4,26 @@
<device>
<match key="info.capabilities" contains="killswitch">
- <append key="info.interfaces" type="strlist">org.freedesktop.Hal.Device.KillSwitch</append>
+ <!-- For IPW WLAN devices we have an own addon -->
+ <match key="killswitch.access_method" string="ipw">
+ <append key="info.addons" type="strlist">hald-addon-ipw-killswitch</append>
+ </match>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_names" type="strlist">SetPower</append>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_signatures" type="strlist">b</append>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_argnames" type="strlist">power</append>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_execpaths" type="strlist">hal-system-killswitch-set-power</append>
+ <!-- For all other KillSwitch devices -->
+ <match key="killswitch.access_method" contains_not="ipw">
+ <append key="info.interfaces" type="strlist">org.freedesktop.Hal.Device.KillSwitch</append>
+
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_names" type="strlist">SetPower</append>
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_signatures" type="strlist">b</append>
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_argnames" type="strlist">power</append>
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_execpaths" type="strlist">hal-system-killswitch-set-power</append>
+
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_names" type="strlist">GetPower</append>
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_signatures" type="strlist"></append>
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_argnames" type="strlist"></append>
+ <append key="org.freedesktop.Hal.Device.KillSwitch.method_execpaths" type="strlist">hal-system-killswitch-get-power</append>
+ </match>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_names" type="strlist">GetPower</append>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_signatures" type="strlist"></append>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_argnames" type="strlist"></append>
- <append key="org.freedesktop.Hal.Device.KillSwitch.method_execpaths" type="strlist">hal-system-killswitch-get-power</append>
</match>
</device>
diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index c30d116..2e03111 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -13,6 +13,7 @@ libexec_PROGRAMS = \
hald-addon-generic-backlight \
hald-addon-hid-ups \
hald-addon-input \
+ hald-addon-ipw-killswitch \
hald-addon-storage
if HAVE_PMU
@@ -97,3 +98,6 @@ hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
hald_addon_generic_backlight_SOURCES = addon-generic-backlight.c ../../logger.c ../../util_helper.c ../../util_helper_priv.c
hald_addon_generic_backlight_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
+hald_addon_ipw_killswitch_SOURCES = addon-ipw-killswitch.c ../../logger.c ../../util_helper.c ../../util_helper_priv.c
+hald_addon_ipw_killswitch_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
+
diff --git a/hald/linux/addons/addon-ipw-killswitch.c b/hald/linux/addons/addon-ipw-killswitch.c
new file mode 100644
index 0000000..674fb9d
--- /dev/null
+++ b/hald/linux/addons/addon-ipw-killswitch.c
@@ -0,0 +1,305 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * addon-generic-backlight.c:
+ * Copyright (C) 2008 Danny Kukawka <danny.kukawka at web.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <glib.h>
+#include <glib/gmain.h>
+#include <glib/gstdio.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
+#include "../../util_helper_priv.h"
+
+static GMainLoop *main_loop;
+static LibHalContext *halctx = NULL;
+static DBusConnection *conn;
+
+const char *udi = NULL;
+const char *path = NULL;
+
+static gboolean
+init_killswitch ()
+{
+ DBusError error;
+ char *parent;
+ char *iface;
+ char *_path;
+ char **udis;
+ int i, num_udis;
+ gboolean ret;
+
+ ret = FALSE;
+
+ dbus_error_init (&error);
+
+ parent = libhal_device_get_property_string (halctx, udi, "info.parent", &error);
+ udis = libhal_manager_find_device_string_match (halctx, "info.parent", parent, &num_udis, &error);
+
+ for (i = 0; i < num_udis; i++) {
+
+ if (strcmp (udis[i], udi) == 0)
+ continue;
+
+ iface = libhal_device_get_property_string (halctx, udis[i], "net.interface", &error);
+ if (iface != NULL) {
+ _path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
+
+ /* check if the file exists */
+ if(g_file_test(_path, G_FILE_TEST_EXISTS) && g_file_test(_path, G_FILE_TEST_IS_REGULAR)) {
+ path = g_strdup (_path);
+ ret = TRUE;
+ }
+
+ g_free (_path);
+ libhal_free_string (iface);
+ }
+ }
+
+ libhal_free_string (parent);
+ libhal_free_string_array (udis);
+
+ return ret;
+}
+
+/* Getting status of the killswitch */
+static int
+get_killswitch ()
+{
+ FILE *f;
+ char buf[64];
+ int kill_status;
+ int ret = -1;
+
+ f = NULL;
+
+ if ((f = fopen (path, "r")) == NULL) {
+ HAL_WARNING(("Could not read killswitch status from '%s'", path));
+ return -1;
+ }
+
+ if (fgets (buf, sizeof (buf), f) == NULL) {
+ HAL_ERROR (("Cannot read from '%s'", path));
+ goto out;
+ }
+
+ errno = 0;
+ kill_status = strtol (buf, NULL, 10);
+ if (errno == 0) {
+ switch(kill_status) {
+ case 0:
+ ret = 1;
+ break;
+ case 1:
+ case 2:
+ case 3:
+ ret = 0;
+ break;
+ default:
+ break;
+ }
+ }
+
+out:
+ if (f != NULL)
+ fclose (f);
+
+ return ret;
+}
+
+/* Setting status of the killswitch */
+static int
+set_killswitch (gboolean status)
+{
+ FILE *f;
+ int ret;
+
+ if ((f = fopen (path, "w")) == NULL) {
+ HAL_WARNING(("Could not open '%s'", path));
+ return -1;
+ }
+
+ if (status) {
+ ret = fputc (0, f);
+ } else {
+ ret = fputc (1, f);
+ }
+
+ if (ret == EOF) {
+ HAL_WARNING(("Could write status to '%s'", path));
+ ret = -1;
+ } else {
+ ret = 0;
+ }
+
+ if (f != NULL)
+ fclose (f);
+
+ return ret;
+}
+
+/* DBus filter function */
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
+{
+ DBusError err;
+ DBusMessage *reply;
+
+ if (!check_priv (halctx, connection, message, dbus_message_get_path (message),
+ "org.freedesktop.hal.killswitch.wlan")) {
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ reply = NULL;
+
+ if (dbus_message_is_method_call (message,
+ "org.freedesktop.Hal.Device.KillSwitch",
+ "SetPower")) {
+ gboolean status;
+
+ dbus_error_init (&err);
+ if (dbus_message_get_args (message,
+ &err,
+ DBUS_TYPE_BOOLEAN, &status,
+ DBUS_TYPE_INVALID)) {
+ int return_code = 0;
+ int set;
+
+ set = set_killswitch (status);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ goto error;
+
+ if (set != 0)
+ return_code = 1;
+
+ dbus_message_append_args (reply,
+ DBUS_TYPE_INT32, &return_code,
+ DBUS_TYPE_INVALID);
+
+ dbus_connection_send (connection, reply, NULL);
+ }
+ } else if (dbus_message_is_method_call (message,
+ "org.freedesktop.Hal.Device.KillSwitch",
+ "GetPower")) {
+ int status;
+
+ dbus_error_init (&err);
+ if (dbus_message_get_args (message,
+ &err,
+ DBUS_TYPE_INVALID)) {
+ status = get_killswitch();
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ goto error;
+
+ dbus_message_append_args (reply,
+ DBUS_TYPE_INT32, &status,
+ DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ }
+ }
+
+error:
+ if (reply != NULL)
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+int
+main (int argc, char *argv[])
+{
+ DBusError err;
+ char *method;
+
+ setup_logger ();
+ udi = getenv ("UDI");
+ method = getenv ("HAL_PROP_KILLSWITCH_ACCESS_METHOD");
+
+ HAL_DEBUG (("udi='%s'", udi));
+ if (udi == NULL) {
+ HAL_ERROR (("No device specified"));
+ return -2;
+ }
+
+ if (strcmp (method, "ipw") != 0) {
+ HAL_ERROR (("Wrong killswitch.access_method '%s', should be 'ipw'", method));
+ return -2;
+ }
+
+ dbus_error_init (&err);
+ if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
+ HAL_ERROR (("Cannot connect to hald"));
+ return -3;
+ }
+
+ conn = libhal_ctx_get_dbus_connection (halctx);
+ dbus_connection_setup_with_g_main (conn, NULL);
+
+ dbus_connection_add_filter (conn, filter_function, NULL, NULL);
+
+ if (!init_killswitch())
+ return -4;
+
+ if (!libhal_device_claim_interface (halctx,
+ udi,
+ "org.freedesktop.Hal.Device.KillSwitch",
+ " <method name=\"SetPower\">\n"
+ " <arg name=\"value\" direction=\"in\" type=\"b\"/>\n"
+ " <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
+ " </method>\n"
+ " <method name=\"GetPower\">\n"
+ " <arg name=\"value\" direction=\"out\" type=\"i\"/>\n"
+ " </method>\n",
+ &err)) {
+ HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.KillSwitch'"));
+ return -5;
+ }
+
+ dbus_error_init (&err);
+ if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
+ return -5;
+ }
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (main_loop);
+ return 0;
+}
diff --git a/tools/linux/Makefile.am b/tools/linux/Makefile.am
index 426078d..6122314 100644
--- a/tools/linux/Makefile.am
+++ b/tools/linux/Makefile.am
@@ -15,12 +15,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) -I$(top_srcdir)/libhal -I$(top_srcdir)/libhal-storage \
@DBUS_CFLAGS@ @GLIB_CFLAGS@ @POLKIT_CFLAGS@
-libexec_PROGRAMS = \
- hal-ipw-killswitch-linux
-
-hal_ipw_killswitch_linux_SOURCES = hal-ipw-killswitch-linux.c
-hal_ipw_killswitch_linux_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
-
+libexec_PROGRAMS =
scriptdir = $(libdir)/hal/scripts/linux
diff --git a/tools/linux/hal-ipw-killswitch-linux.c b/tools/linux/hal-ipw-killswitch-linux.c
deleted file mode 100644
index 3b14933..0000000
--- a/tools/linux/hal-ipw-killswitch-linux.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/***************************************************************************
- * CVSID: $Id$
- *
- * Copyright (C) 2007 Adel Gadllah <adel.gadllah at gmail.com>
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <syslog.h>
-#include <glib.h>
-#include <stdlib.h>
-
-#include <libhal.h>
-
-static LibHalContext *hal_ctx;
-
-int main(int argc,char** argv) {
-
- DBusError error;
-
- char *udi;
- char *parent;
- char *iface;
- int i, kill_status;
- char **udis;
- int num_udis;
- FILE *fd;
- char *path;
- int ret = -1;
-
- if (argc == 1)
- return -1;
-
- dbus_error_init (&error);
-
- if ((udi = getenv ("HAL_PROP_INFO_UDI")) == NULL) return -1;
-
- if ((hal_ctx = libhal_ctx_new ()) == NULL) {
- syslog (LOG_INFO, "error: libhal_ctx_new\n");
- return -1;
- }
-
- if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
- syslog (LOG_INFO, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
- LIBHAL_FREE_DBUS_ERROR (&error);
- return -1;
- }
-
- if (!libhal_ctx_init (hal_ctx, &error)) {
- syslog (LOG_INFO, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
- LIBHAL_FREE_DBUS_ERROR (&error);
- return -1;
- }
-
-
- parent = libhal_device_get_property_string (hal_ctx, udi, "info.parent", &error);
- udis = libhal_manager_find_device_string_match (hal_ctx, "info.parent", parent, &num_udis, &error);
-
- if( argc==2 && strcmp("getrfkill",argv[1])==0) {
-
- for (i = 0; i < num_udis; i++) {
- char buf[64];
-
- if (strcmp (udis[i], udi) == 0)
- continue;
-
- iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
- if (iface != NULL) {
- path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
-
- if ((fd = fopen (path, "r")) == NULL) {
- return -1;
- }
- if (fgets (buf, sizeof (buf), fd) == NULL) {
- return -1;
- }
-
- errno = 0;
- kill_status = strtol (buf, NULL, 10);
- if (errno == 0) {
- /* syslog (LOG_INFO, "'%s' returned %d", path, kill_status); */
-
- switch(kill_status) {
- case 0:
- ret = 0;
- break;
- case 1:
- case 2:
- case 3:
- ret = 1;
- break;
- default:
- break;
- }
- }
-
- fclose (fd);
- g_free (path);
- libhal_free_string (iface);
- }
- }
- }
-
- if (argc == 3 && strcmp ("setrfkill", argv[1]) == 0 && (atoi (argv[2]) == 0 || atoi(argv[2]) == 1)) {
-
- for (i = 0; i < num_udis; i++) {
- if (strcmp (udis[i], udi) == 0)
- continue;
-
- iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
- if (iface != NULL) {
- path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", iface);
-
- if ((fd = fopen (path, "w")) == NULL) {
- return -1;
- }
-
- fputc (argv[2][0], fd);
- fclose (fd);
-
- g_free (path);
- libhal_free_string (iface);
- }
- }
-
- ret = 0;
- }
-
- libhal_free_string (parent);
- libhal_free_string_array (udis);
- libhal_ctx_free (hal_ctx);
-
- if (dbus_error_is_set (&error)) {
- syslog (LOG_INFO, "error: %s: %s\n", error.name, error.message);
- dbus_error_free (&error);
- return -1;
- }
-
- return ret;
-}
diff --git a/tools/linux/hal-system-killswitch-get-power-linux b/tools/linux/hal-system-killswitch-get-power-linux
index 70dbb20..7892d0c 100755
--- a/tools/linux/hal-system-killswitch-get-power-linux
+++ b/tools/linux/hal-system-killswitch-get-power-linux
@@ -75,18 +75,6 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wlan" ]; then
echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
exit 1
fi
- elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ]; then
- hal-ipw-killswitch-linux getrfkill
- value=$?
- if [ "$value" = "0" ]; then
- exit 1
- elif [ "$value" = "1" ]; then
- exit 0
- else
- echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "hal-ipw-killswitch-linux returned $value" >&2
- exit 1
- fi
else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
echo "Access type not supported" >&2
diff --git a/tools/linux/hal-system-killswitch-set-power-linux b/tools/linux/hal-system-killswitch-set-power-linux
index bc2ed38..f160c66 100755
--- a/tools/linux/hal-system-killswitch-set-power-linux
+++ b/tools/linux/hal-system-killswitch-set-power-linux
@@ -85,19 +85,6 @@ elif [ "$HAL_PROP_KILLSWITCH_TYPE" = "wlan" ]; then
echo "dellWirelessCtl ($DELL_WCTL) not available or executable" >&2
exit 1
fi
- elif [ "$HAL_PROP_KILLSWITCH_ACCESS_METHOD" = "ipw" ]; then
- if [ "$value" = "true" ]; then
- rf_value=0
- elif [ "$value" = "false" ]; then
- rf_value=1
- fi
- hal-ipw-killswitch-linux setrfkill $rf_value
- ret=$?
- if [ "$ret" != "0" ]; then
- echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
- echo "hal-ipw-killswitch-linux returned $value" >&2
- exit 1
- fi
else
echo "org.freedesktop.Hal.Device.KillSwitch.NotSupported" >&2
echo "Access type not supported" >&2
More information about the hal-commit
mailing list