Windows: Set device number for root hubs to 1
authorPete Batard <pete@akeo.ie>
Wed, 18 Jul 2012 17:25:11 +0000 (18:25 +0100)
committerPete Batard <pete@akeo.ie>
Wed, 18 Jul 2012 17:25:11 +0000 (18:25 +0100)
* 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 for just in case.

libusb/os/windows_usb.c
libusb/version_nano.h

index 8615039..8829da4 100644 (file)
@@ -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);
        }
 
index 4e1e808..ec7e590 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10540
+#define LIBUSB_NANO 10541