[PATCH libwacom 0/5] uinput support hacks

View: New views
6 Messages — Rating Filter:   Alert me  

[PATCH libwacom 0/5] uinput support hacks

by Peter Hutterer-3 :: Rate this Message:

| View Threaded | Show Only this Message


A set of patches to allow libwacom to handle uinput devices. This makes it a
lot easier to test, especially for those poor sods that can't afford to have
every single device ever made collecting dust on their desk :)

I'd have preferred a override of SUBSYSTEM in udev but that's now allowed so
we have to do with custom properties.

Cheers,
  Peter


------------------------------------------------------------------------------
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

[PATCH libwacom 1/5] lib: if no subsystem matches, don't access invalid devices

by Peter Hutterer-3 :: Rate this Message:

| View Threaded | Show Only this Message

For evemu devices, the subsystem is only input until we arrive at the NULL
parent. If that's the case, don't try to get the subsystem from a NULL
pointer but return a unknown subsystem instead.

Signed-off-by: Peter Hutterer <peter.hutterer@...>
---
 libwacom/libwacom.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 811948a..103f942 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -60,17 +60,20 @@ get_bus (GUdevDevice *device)
  while (parent && g_strcmp0 (subsystem, "input") == 0) {
  GUdevDevice *old_parent = parent;
  parent = g_udev_device_get_parent (old_parent);
- subsystem = g_udev_device_get_subsystem (parent);
+ if (parent)
+ subsystem = g_udev_device_get_subsystem (parent);
  g_object_unref (old_parent);
  }
 
- if (g_strcmp0 (subsystem, "tty") == 0 || g_strcmp0 (subsystem, "serio") == 0)
- bus_str = g_strdup ("serial");
- else
- bus_str = g_strdup (subsystem);
+ if (parent) {
+ if (g_strcmp0 (subsystem, "tty") == 0 || g_strcmp0 (subsystem, "serio") == 0)
+ bus_str = g_strdup ("serial");
+ else
+ bus_str = g_strdup (subsystem);
 
- if (parent)
  g_object_unref (parent);
+ } else
+ bus_str = strdup("unknown");
 
  return bus_str;
 }
--
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

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

by Peter Hutterer-3 :: Rate this Message:

| View Threaded | Show Only this Message

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

[PATCH libwacom 3/5] lib: check for UINPUT_ properties to allow for emulated devices

by Peter Hutterer-3 :: Rate this Message:

| View Threaded | Show Only this Message

Emulating devices is important for debugging when the hardware isn't
present. udev doesn't apply the same settings to emulated uinput devices as
it does to real devices, so we need to guess.

To allow some flexibility, use an UINPUT_ namespace and check that. Custom
udev rules may then set the UINPUT_SUBSYSTEM for an emulated device.

Signed-off-by: Peter Hutterer <peter.hutterer@...>
---
 libwacom/libwacom.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 103f942..93695cb 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -47,6 +47,34 @@ is_tablet_or_touchpad (GUdevDevice *device)
  g_udev_device_get_property_as_boolean (device, "ID_INPUT_TOUCHPAD");
 }
 
+/* Overriding SUBSYSTEM isn't allowed in udev (works sometimes, but not
+ * always). For evemu devices we need to set custom properties to make them
+ * detected by libwacom.
+ */
+static char *
+get_uinput_subsystem (GUdevDevice *device)
+{
+ const char *bus_str;
+ GUdevDevice *parent;
+
+
+ bus_str = NULL;
+ parent = g_object_ref (device);
+
+ while (parent && !g_udev_device_get_property_as_boolean (parent, "UINPUT_DEVICE")) {
+ GUdevDevice *old_parent = parent;
+ parent = g_udev_device_get_parent (old_parent);
+ g_object_unref (old_parent);
+ }
+
+ if (parent) {
+ bus_str = g_udev_device_get_property (parent, "UINPUT_SUBSYSTEM");
+ g_object_unref (parent);
+ }
+
+ return bus_str ? g_strdup (bus_str) : NULL;
+}
+
 static char *
 get_bus (GUdevDevice *device)
 {
@@ -54,6 +82,10 @@ get_bus (GUdevDevice *device)
  char *bus_str;
  GUdevDevice *parent;
 
+ bus_str = get_uinput_subsystem (device);
+ if (bus_str)
+ return bus_str;
+
  subsystem = g_udev_device_get_subsystem (device);
  parent = g_object_ref (device);
 
--
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

[PATCH libwacom 4/5] lib: if we can't get vendor/product, try again on the parent

by Peter Hutterer-3 :: Rate this Message:

| View Threaded | Show Only this Message

This happens with uinput custom-labelled devices.

Signed-off-by: Peter Hutterer <peter.hutterer@...>
---
 libwacom/libwacom.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 93695cb..821e3ee 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -185,12 +185,27 @@ get_device_info (const char   *path,
  *bus = bus_from_str (bus_str);
  if (*bus == WBUSTYPE_USB) {
  const char *vendor_str, *product_str;
+ GUdevDevice *parent;
 
  vendor_str = g_udev_device_get_property (device, "ID_VENDOR_ID");
  product_str = g_udev_device_get_property (device, "ID_MODEL_ID");
 
+ parent = NULL;
+ /* uinput devices have the props set on the parent, there is
+ * nothing a a udev rule can match on on the child */
+ if (!vendor_str || !product_str) {
+ parent = g_udev_device_get_parent (device);
+ if (parent) {
+ vendor_str = g_udev_device_get_property (parent, "ID_VENDOR_ID");
+ product_str = g_udev_device_get_property (parent, "ID_MODEL_ID");
+ }
+ }
+
  *vendor_id = strtol (vendor_str, NULL, 16);
  *product_id = strtol (product_str, NULL, 16);
+
+ if (parent)
+ g_object_unref (parent);
  } else if (*bus == WBUSTYPE_BLUETOOTH || *bus == WBUSTYPE_SERIAL) {
  GUdevDevice *parent;
  const char *product_str;
--
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

[PATCH libwacom 5/5] README: provide a description on how to debug uinput devices

by Peter Hutterer-3 :: Rate this Message:

| View Threaded | Show Only this Message

Signed-off-by: Peter Hutterer <peter.hutterer@...>
---
 README |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/README b/README
index 39f0503..525412e 100644
--- a/README
+++ b/README
@@ -1,3 +1,20 @@
 libwacom is a library to identify wacom tablets and their model-specific
 features. It provides easy access to information such as "is this a built-in
 on-screen tablet", "what is the size of this model", etc.
+
+== Debugging libwacom with uinput devices ==
+libwacom by default will not recognise uinput devices. To debug and test, a
+physical device must be connected.
+
+Custom udev rules are provided to help debug uinput device. Run
+    generate-udev-rules --with-uinput-rules
+to generate these rules and apply them locally. Devices will then be tagged
+as required and can be debugged.
+
+Some limitations:
+* For these rules to work, the device must be listed in the database.
+* libwacom will check UINPUT_* properties on the uinput device, if they do
+  not get applied, the device will not be visible
+
+DO NOT USE THESE UINPUT RULES unless you are debugging with uinput devices.
+Remove the rules once debugging is done.
--
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