WARNING: This server is unstable and will be retired in the next days. If you want to keep this forum available, please request immediately a migration on the Nabble Support forum. Forums that don't receive any migration request will be deleted forever.

 « Return to Thread: [PATCH libwacom 0/5] uinput support hacks

[PATCH libwacom 2/5] Generate extra udev rules to assing fields to uinput devices

by Peter Hutterer-3 :: Rate this Message:

| View in Thread

uinput devices aren't processed like other devices in udev, they don't get
the right hierarchy and not all the properties are assigned.
uinput devices are useful for debugging where the hardware isn't available
though.

Add a --with-uinput-rules flag to the generate-udev-rules helper tool to
write a rule for each device in the database to apply extra properties if
that device were a virtual device.

New properties assigned:
  ENV{UINPUT_DEVICE}="1"
  ENV{UINPUT_SUBSYSTEM}="<subsystem>"

(udev doesn't allow overriding the subystem)

Other properties assigned:
  ENV{ID_VENDOR_ID}
  ENV{ID_MODEL_ID}

Note that these properties will be available on the parent only, there is
nothing on the child we can match on.

Signed-off-by: Peter Hutterer <peter.hutterer@...>
---
 tools/Makefile.am           |    3 +-
 tools/generate-udev-rules.c |   73 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/tools/Makefile.am b/tools/Makefile.am
index a6fa8b4..c204ab0 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -2,7 +2,8 @@ AM_CPPFLAGS=-I$(top_srcdir)/libwacom -DTOPSRCDIR="\"$(top_srcdir)\""
 
 noinst_PROGRAMS = generate-udev-rules list-devices
 generate_udev_rules_SOURCES = generate-udev-rules.c
-generate_udev_rules_LDADD=$(top_builddir)/libwacom/libwacom.la
+generate_udev_rules_LDADD=$(top_builddir)/libwacom/libwacom.la $(GLIB_LIBS)
+generate_udev_rules_CFLAGS=$(GLIB_CFLAGS)
 
 list_devices_SOURCES = list-devices.c
 list_devices_LDADD=$(top_builddir)/libwacom/libwacom.la
diff --git a/tools/generate-udev-rules.c b/tools/generate-udev-rules.c
index bc1d7a2..28650d5 100644
--- a/tools/generate-udev-rules.c
+++ b/tools/generate-udev-rules.c
@@ -29,8 +29,18 @@
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include "libwacom.h"
+#include <glib/gi18n.h>
+#include <glib.h>
+
+static gboolean need_uinput_rules = FALSE;
+
+static GOptionEntry opts[] = {
+        {"with-uinput-rules", 0, 0, G_OPTION_ARG_NONE, &need_uinput_rules, N_("Print udev rules for uinput devices"), NULL },
+ {NULL}
+};
 
 static void print_udev_header (void)
 {
@@ -73,6 +83,45 @@ static void print_udev_entry_for_match (WacomDevice *device, const WacomMatch *m
  }
 }
 
+static void print_uinput_entry_for_match (WacomDevice *device, const WacomMatch *match,
+  WacomBusType bus_type_filter)
+{
+ WacomBusType type       = libwacom_match_get_bustype (match);
+ int          vendor     = libwacom_match_get_vendor_id (match);
+ int          product    = libwacom_match_get_product_id (match);
+ const char *subsystem;
+
+ if (bus_type_filter != type)
+ return;
+
+ switch(type) {
+ case WBUSTYPE_USB: subsystem = "usb"; break;
+ case WBUSTYPE_BLUETOOTH: subsystem = "bluetooth"; break;
+ case WBUSTYPE_SERIAL: subsystem = "tty"; break;
+ default:
+      return;
+ }
+
+ printf("ENV{DEVPATH}==\"/devices/virtual/*\", "
+ "ENV{PRODUCT}==\"*/%x/%x/*\", "
+ "ENV{UINPUT_DEVICE}=\"1\", "
+ "ENV{UINPUT_SUBSYSTEM}=\"%s\", "
+ "ENV{ID_VENDOR_ID}=\"%04x\", "
+ "ENV{ID_MODEL_ID}=\"%04x\", "
+ "\n", vendor, product,
+ subsystem, vendor, product);
+}
+
+static void print_uinput_entry (WacomDevice *device, WacomBusType bus_type_filter)
+{
+ const WacomMatch **matches, **match;
+
+ matches = libwacom_get_matches(device);
+ for (match = matches; *match; match++)
+ print_uinput_entry_for_match(device, *match, bus_type_filter);
+}
+
+
 static void print_udev_entry (WacomDevice *device, WacomBusType bus_type_filter)
 {
  const WacomMatch **matches, **match;
@@ -97,6 +146,22 @@ int main(int argc, char **argv)
 {
  WacomDeviceDatabase *db;
  WacomDevice **list, **p;
+ GOptionContext *context;
+ GError *error;
+
+ context = g_option_context_new (NULL);
+
+ g_option_context_add_main_entries (context, opts, NULL);
+ error = NULL;
+
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ if (error != NULL) {
+ fprintf (stderr, "%s\n", error->message);
+ g_error_free (error);
+ }
+ return EXIT_FAILURE;
+ }
+
 
  db = libwacom_database_new_for_path(TOPSRCDIR"/data");
 
@@ -109,11 +174,19 @@ int main(int argc, char **argv)
  print_udev_header ();
  for (p = list; *p; p++)
  print_udev_entry ((WacomDevice *) *p, WBUSTYPE_USB);
+
  print_udev_trailer ();
 
  for (p = list; *p; p++)
  print_udev_entry ((WacomDevice *) *p, WBUSTYPE_BLUETOOTH);
 
+ if (need_uinput_rules) {
+ for (p = list; *p; p++)
+ print_uinput_entry ((WacomDevice *) *p, WBUSTYPE_USB);
+ for (p = list; *p; p++)
+ print_uinput_entry ((WacomDevice *) *p, WBUSTYPE_BLUETOOTH);
+ }
+
  libwacom_database_destroy (db);
 
  return 0;
--
1.7.10.1


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@...
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

 « Return to Thread: [PATCH libwacom 0/5] uinput support hacks