On 2012.07.16 19:06, Pete Batard wrote:
I have now logged an enhancement [1], currently targeted at 1.0.14, to
see if we can ensure that root hubs identified by libusbx always have
the same address, across all platforms.
As part of this enhancement, the attached patch will ensure that root
hubs are set with device address 1 on Windows, instead of 255, to align
this platform with the behaviour observed on Linux and OS-X.
Regards,
/Pete
[1] https://github.com/libusbx/libusbx/issues/36
>From 8cd30bb7066f785ee78cf6c3dccafdbc4b957b50 Mon Sep 17 00:00:00 2001
From: Pete Batard <p...@akeo.ie>
Date: Wed, 18 Jul 2012 18:25:11 +0100
Subject: [PATCH] Windows: Set device number for root hubs to 1
* Other platforms (Linux, OS-X) appear to use 1 => follow suit.
* For non root hub devices, we simply increment the USB device address.
* Collisions with device address 0 are not expected, but we add
an assertion just in case.
---
libusb/os/windows_usb.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 8615039..8829da4 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -1067,7 +1067,10 @@ static int init_device(struct libusb_device* dev, struct
libusb_device* parent_d
if (conn_info.DeviceAddress > UINT8_MAX) {
usbi_err(ctx, "program assertion failed: device address
overflow");
}
- dev->device_address = (uint8_t)conn_info.DeviceAddress;
+ dev->device_address = (uint8_t)conn_info.DeviceAddress + 1;
+ if (dev->device_address == 1) {
+ usbi_err(ctx, "program assertion failed: device address
collision with root hub");
+ }
switch (conn_info.Speed) {
case 0: dev->speed = LIBUSB_SPEED_LOW; break;
case 1: dev->speed = LIBUSB_SPEED_FULL; break;
@@ -1078,7 +1081,7 @@ static int init_device(struct libusb_device* dev, struct
libusb_device* parent_d
break;
}
} else {
- dev->device_address = UINT8_MAX; // Hubs from HCD have a
devaddr of 255
+ dev->device_address = 1; // root hubs are set to use
device number 1
force_hcd_device_descriptor(dev);
}
--
1.7.11.msysgit.0
------------------------------------------------------------------------------
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/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel