diff options
author | Pete Batard <pbatard@gmail.com> | 2011-03-03 18:35:35 +0000 |
---|---|---|
committer | Peter Stuge <peter@stuge.se> | 2011-09-15 15:16:20 +0200 |
commit | 0288bf24f91eca9f433ebad91a7eb6c0e3e29133 (patch) | |
tree | 64d0f0295ce2387ea6f32e49eb263c8245f35fcd | |
parent | 382b7deaadd7e2f1d08c9e921e460bb3abf130b2 (diff) | |
download | libusb-0288bf24f91eca9f433ebad91a7eb6c0e3e29133.tar.gz |
Windows: Provide libusb_get_device_speed() data
* use (currently superspeed unaware) USB_NODE_CONNECTION_INFORMATION_EX
Fixes #45.
[stuge: Explicitly convert OS device speeds to libusb device speeds]
[pbatard: Add breaks overlooked when adding explicit conversion]
-rw-r--r-- | libusb/os/windows_usb.c | 14 | ||||
-rw-r--r-- | libusb/os/windows_usb.h | 14 |
2 files changed, 19 insertions, 9 deletions
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 873a9ba..7f10f87 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -980,7 +980,7 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d { HANDLE handle; DWORD size; - USB_NODE_CONNECTION_INFORMATION conn_info; + USB_NODE_CONNECTION_INFORMATION_EX conn_info; struct windows_device_priv *priv, *parent_priv; struct libusb_context *ctx = DEVICE_CTX(dev); struct libusb_device* tmp_dev; @@ -1030,9 +1030,9 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d usbi_warn(ctx, "could not open hub %s: %s", parent_priv->path, windows_error_str(0)); return LIBUSB_ERROR_ACCESS; } - size = sizeof(USB_NODE_CONNECTION_INFORMATION); + size = sizeof(conn_info); conn_info.ConnectionIndex = (ULONG)port_number; - if (!DeviceIoControl(handle, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION, &conn_info, size, + if (!DeviceIoControl(handle, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, &conn_info, size, &conn_info, size, &size, NULL)) { usbi_warn(ctx, "could not get node connection information for device '%s': %s", device_id, windows_error_str(0)); @@ -1060,6 +1060,14 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d usbi_err(ctx, "program assertion failed: device address overflow"); } dev->device_address = (uint8_t)conn_info.DeviceAddress; + switch (conn_info.Speed) { + case 0: dev->speed = LIBUSB_SPEED_LOW; break; + case 1: dev->speed = LIBUSB_SPEED_FULL; break; + case 2: dev->speed = LIBUSB_SPEED_HIGH; break; + default: + usbi_warn(ctx, "Got unknown device speed %d", conn_info.Speed); + break; + } } else { dev->device_address = UINT8_MAX; // Hubs from HCD have a devaddr of 255 force_hcd_device_descriptor(dev); diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h index 6f930d5..608f369 100644 --- a/libusb/os/windows_usb.h +++ b/libusb/os/windows_usb.h @@ -317,10 +317,12 @@ typedef RETURN_TYPE CONFIGRET; #define USB_REQUEST_SYNC_FRAME LIBUSB_REQUEST_SYNCH_FRAME #define USB_GET_NODE_INFORMATION 258 -#define USB_GET_NODE_CONNECTION_INFORMATION 259 #define USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION 260 #define USB_GET_NODE_CONNECTION_NAME 261 #define USB_GET_HUB_CAPABILITIES 271 +#if !defined(USB_GET_NODE_CONNECTION_INFORMATION_EX) +#define USB_GET_NODE_CONNECTION_INFORMATION_EX 274 +#endif #if !defined(USB_GET_HUB_CAPABILITIES_EX) #define USB_GET_HUB_CAPABILITIES_EX 276 #endif @@ -381,8 +383,8 @@ DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDA, (DEVINST, PCHAR, ULONG, ULONG) #define IOCTL_USB_GET_NODE_INFORMATION \ CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION \ - CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX \ + CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_INFORMATION_EX, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES \ CTL_CODE(FILE_DEVICE_USB, USB_GET_NODE_CONNECTION_ATTRIBUTES, METHOD_BUFFERED, FILE_ANY_ACCESS) @@ -512,17 +514,17 @@ typedef struct _USB_PIPE_INFO { ULONG ScheduleOffset; } USB_PIPE_INFO, *PUSB_PIPE_INFO; -typedef struct _USB_NODE_CONNECTION_INFORMATION { +typedef struct _USB_NODE_CONNECTION_INFORMATION_EX { ULONG ConnectionIndex; USB_DEVICE_DESCRIPTOR DeviceDescriptor; UCHAR CurrentConfigurationValue; - BOOLEAN LowSpeed; + UCHAR Speed; BOOLEAN DeviceIsHub; USHORT DeviceAddress; ULONG NumberOfOpenPipes; USB_CONNECTION_STATUS ConnectionStatus; // USB_PIPE_INFO PipeList[0]; -} USB_NODE_CONNECTION_INFORMATION, *PUSB_NODE_CONNECTION_INFORMATION; +} USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX; typedef struct _USB_HUB_CAP_FLAGS { ULONG HubIsHighSpeedCapable:1; |