From 4c9102961d3a0df21f66ad2e8ff20dee0fc9290d Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 1 Dec 2010 12:41:56 +0000 Subject: unconstrained ancestors lookup for HID and other devices * Some HID devices (Logitech) had interfaces that used more than 2 levels to get to a listed ancestor, which resulted to assertion failure * new implementation no longer constrains lookup level * issue reported by Phong Truong --- configure.ac | 2 +- libusb/libusb_version.h | 2 +- libusb/os/windows_usb.c | 44 +++++++++++++------------------------------- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/configure.ac b/configure.ac index 39daa13..1646a8f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ m4_define(LIBUSB_MAJOR, [1]) m4_define(LIBUSB_MINOR, [0]) m4_define(LIBUSB_MICRO, [8]) -m4_define(LIBUSB_NANO, [10323]) +m4_define(LIBUSB_NANO, [10324]) AC_INIT([libusb], LIBUSB_MAJOR.LIBUSB_MINOR.LIBUSB_MICRO, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/]) diff --git a/libusb/libusb_version.h b/libusb/libusb_version.h index 338ba1a..7f5f839 100644 --- a/libusb/libusb_version.h +++ b/libusb/libusb_version.h @@ -24,6 +24,6 @@ #define LIBUSB_VERSION_MAJOR 1 #define LIBUSB_VERSION_MINOR 0 #define LIBUSB_VERSION_MICRO 8 -#define LIBUSB_VERSION_NANO 10323 +#define LIBUSB_VERSION_NANO 10324 #endif diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 6ad6229..0650f54 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -571,6 +571,7 @@ unsigned long htab_hash(char* str) /* * Returns the session ID of a device's nth level ancestor + * If there's no device at the nth level, return 0 */ static unsigned long get_ancestor_session_id(DWORD devinst, unsigned level) { @@ -590,11 +591,6 @@ static unsigned long get_ancestor_session_id(DWORD devinst, unsigned level) if (CM_Get_Device_IDA(devinst, path, MAX_PATH_LENGTH, 0) != CR_SUCCESS) { return 0; } - // Return a special invalid session ID if the GP is not USB (as can be the case for HID) - if ((level == 2) && (path[0] != 'U') && (path[1] != 'S') && (path[2] != 'B')) { - usbi_dbg("detected non USB parent '%s'", path); - return ~0; - } // TODO (post hotplug): try without sanitizing sanitized_path = sanitize_path(path); if (sanitized_path == NULL) { @@ -1267,7 +1263,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered #define DEV_PASS 3 #define HID_PASS 4 int r = LIBUSB_SUCCESS; - unsigned int nb_guids, pass, i, j; + unsigned int nb_guids, pass, i, j, ancestor; char path[MAX_PATH_LENGTH]; char strbuf[MAX_PATH_LENGTH]; struct libusb_device *dev, *parent_dev; @@ -1456,35 +1452,21 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered case HUB_PASS: break; default: - session_id = get_ancestor_session_id(dev_info_data.DevInst, 1); - if (session_id == 0) { - usbi_err(ctx, "program assertion failed: orphan device '%s'", dev_id_path); - LOOP_BREAK(LIBUSB_ERROR_NO_DEVICE); - } - parent_dev = usbi_get_device_by_session_id(ctx, session_id); - // Composite HID devices have double indirection => Check grandparent - if (pass == HID_PASS) { - session_id = get_ancestor_session_id(dev_info_data.DevInst, 2); + // Go through the ancestors until we see a face we recognize + parent_dev = NULL; + for (ancestor = 1; parent_dev == NULL; ancestor++) { + session_id = get_ancestor_session_id(dev_info_data.DevInst, ancestor); if (session_id == 0) { - usbi_err(ctx, "program assertion failed: no grandparent for '%s'", dev_id_path); - LOOP_BREAK(LIBUSB_ERROR_NO_DEVICE); - } else if (session_id == ~0) { - usbi_dbg("skipping non USB HID interface '%s'", dev_id_path); - continue; - } - dev = usbi_get_device_by_session_id(ctx, session_id); - if (dev == NULL) { - usbi_err(ctx, "program assertion failed: unlisted grandparent for '%s'", dev_id_path); - LOOP_BREAK(LIBUSB_ERROR_NO_DEVICE); - } - if (__device_priv(dev)->apib->id == USB_API_COMPOSITE) { - parent_dev = dev; + usbi_err(ctx, "program assertion failed: orphan device '%s'", dev_id_path); + r = LIBUSB_ERROR_NO_DEVICE; + break; } + parent_dev = usbi_get_device_by_session_id(ctx, session_id); } if (parent_dev == NULL) { - // This can occur if the OS only reports a newly plugged device after we started enum, - // eg. HID parent not listed on GEN pass, but children listed on HID pass - usbi_warn(ctx, "unlisted parent for '%s' (newly connected device?) - ignoring", dev_id_path); + if (session_id != 0) { + usbi_dbg("unlisted ancestor for '%s' (newly connected device, non USB HID, etc.) - ignoring", dev_id_path); + } continue; } parent_priv = __device_priv(parent_dev); -- cgit v1.2.1