summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2010-06-10 06:15:41 -0700
committerPeter Hutterer <peter.hutterer@who-t.net>2010-06-11 09:30:33 +1000
commit87a1507da7e7788232d74285ef377b67b70e0fa4 (patch)
tree5fe21b2ea4299acfad7603259abfd7330781abee /config
parent645679c1523eee7028f3244cee57936b93326a2a (diff)
xfree86: Match devices based on USB ID
Sometimes the vendor and product names aren't specific enough to target a USB device, so expose the numeric codes in the ID. A MatchUSBID entry has been added that supports shell pattern matching when fnmatch(3) is available. For example: MatchUSBID "046d:*" The IDs are stored in lowercase hex separated by a ':' like "lsusb" or "lspci -n". Signed-off-by: Dan Nicholson <dbn.lists@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'config')
-rw-r--r--config/hal.c18
-rw-r--r--config/udev.c20
2 files changed, 38 insertions, 0 deletions
diff --git a/config/hal.c b/config/hal.c
index 806102041..8f9aeb8d3 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -184,7 +184,24 @@ device_added(LibHalContext *hal_ctx, const char *udi)
parent = get_prop_string(hal_ctx, udi, "info.parent");
if (parent) {
+ int usb_vendor, usb_product;
+
attrs.pnp_id = get_prop_string(hal_ctx, parent, "pnp.id");
+
+ /* construct USB ID in lowercase - "0000:ffff" */
+ usb_vendor = libhal_device_get_property_int(hal_ctx, parent,
+ "usb.vendor_id", NULL);
+ LogMessageVerb(X_INFO, 10,
+ "config/hal: getting usb.vendor_id on %s "
+ "returned %04x\n", parent, usb_vendor);
+ usb_product = libhal_device_get_property_int(hal_ctx, parent,
+ "usb.product_id", NULL);
+ LogMessageVerb(X_INFO, 10,
+ "config/hal: getting usb.product_id on %s "
+ "returned %04x\n", parent, usb_product);
+ if (usb_vendor && usb_product)
+ attrs.usb_id = Xprintf("%04x:%04x", usb_vendor, usb_product);
+
free(parent);
}
@@ -391,6 +408,7 @@ unwind:
free(attrs.vendor);
free(attrs.device);
free(attrs.pnp_id);
+ free(attrs.usb_id);
if (attrs.tags) {
char **tag = attrs.tags;
while (*tag) {
diff --git a/config/udev.c b/config/udev.c
index f7ed4b2de..16c462455 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -28,6 +28,7 @@
#endif
#include <libudev.h>
+#include <ctype.h>
#include "input.h"
#include "inputstr.h"
@@ -57,6 +58,7 @@ device_added(struct udev_device *udev_device)
char *config_info = NULL;
const char *syspath;
const char *tags_prop;
+ const char *usb_vendor = NULL, *usb_model = NULL;
const char *key, *value, *tmp;
InputOption *options = NULL, *tmpo;
InputAttributes attrs = {};
@@ -150,6 +152,12 @@ device_added(struct udev_device *udev_device)
} else if (!strcmp(key, "ID_VENDOR")) {
LOG_PROPERTY(path, key, value);
attrs.vendor = value;
+ } else if (!strcmp(key, "ID_VENDOR_ID")) {
+ LOG_PROPERTY(path, key, value);
+ usb_vendor = value;
+ } else if (!strcmp(key, "ID_VENDOR_MODEL")) {
+ LOG_PROPERTY(path, key, value);
+ usb_model = value;
} else if (!strcmp(key, "ID_INPUT_KEY")) {
LOG_PROPERTY(path, key, value);
attrs.flags |= ATTR_KEYBOARD;
@@ -170,6 +178,17 @@ device_added(struct udev_device *udev_device)
attrs.flags |= ATTR_TOUCHSCREEN;
}
}
+
+ /* construct USB ID in lowercase hex - "0000:ffff" */
+ if (usb_vendor && usb_model) {
+ attrs.usb_id = Xprintf("%s:%s", usb_vendor, usb_model);
+ if (attrs.usb_id) {
+ char *cur;
+ for (cur = attrs.usb_id; *cur; cur++)
+ *cur = tolower(*cur);
+ }
+ }
+
LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
name, path);
rc = NewInputDeviceRequest(options, &attrs, &dev);
@@ -190,6 +209,7 @@ device_added(struct udev_device *udev_device)
free(tmpo);
}
+ free(attrs.usb_id);
if (attrs.tags) {
char **tag = attrs.tags;
while (*tag) {