summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libusb/core.c9
-rw-r--r--libusb/descriptor.c22
-rw-r--r--libusb/libusbi.h43
-rw-r--r--libusb/os/darwin_usb.c28
-rw-r--r--libusb/os/haiku_pollfs.cpp5
-rw-r--r--libusb/os/haiku_usb_raw.cpp9
-rw-r--r--libusb/os/linux_usbfs.c19
-rw-r--r--libusb/os/netbsd_usb.c25
-rw-r--r--libusb/os/null_usb.c8
-rw-r--r--libusb/os/openbsd_usb.c23
-rw-r--r--libusb/os/sunos_usb.c38
-rw-r--r--libusb/os/sunos_usb.h1
-rw-r--r--libusb/os/windows_common.c8
-rw-r--r--libusb/os/windows_common.h4
-rw-r--r--libusb/os/windows_usbdk.c21
-rw-r--r--libusb/os/windows_winusb.c54
-rw-r--r--libusb/os/windows_winusb.h4
-rw-r--r--libusb/version_nano.h2
18 files changed, 104 insertions, 219 deletions
diff --git a/libusb/core.c b/libusb/core.c
index 228f898..009d0c8 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -737,12 +737,13 @@ void usbi_disconnect_device(struct libusb_device *dev)
* to the discovered device list. */
int usbi_sanitize_device(struct libusb_device *dev)
{
- int r;
uint8_t num_configurations;
- r = usbi_device_cache_descriptor(dev);
- if (r < 0)
- return r;
+ if (dev->device_descriptor.bLength != LIBUSB_DT_DEVICE_SIZE ||
+ dev->device_descriptor.bDescriptorType != LIBUSB_DT_DEVICE) {
+ usbi_err(DEVICE_CTX(dev), "invalid device descriptor");
+ return LIBUSB_ERROR_IO;
+ }
num_configurations = dev->device_descriptor.bNumConfigurations;
if (num_configurations > USB_MAXCONFIG) {
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index ac3faaa..08ed554 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -482,24 +482,6 @@ static int raw_desc_to_config(struct libusb_context *ctx,
return LIBUSB_SUCCESS;
}
-int usbi_device_cache_descriptor(libusb_device *dev)
-{
- int r, host_endian = 0;
-
- r = usbi_backend.get_device_descriptor(dev, &dev->device_descriptor, &host_endian);
- if (r < 0)
- return r;
-
- if (!host_endian) {
- dev->device_descriptor.bcdUSB = libusb_le16_to_cpu(dev->device_descriptor.bcdUSB);
- dev->device_descriptor.idVendor = libusb_le16_to_cpu(dev->device_descriptor.idVendor);
- dev->device_descriptor.idProduct = libusb_le16_to_cpu(dev->device_descriptor.idProduct);
- dev->device_descriptor.bcdDevice = libusb_le16_to_cpu(dev->device_descriptor.bcdDevice);
- }
-
- return LIBUSB_SUCCESS;
-}
-
/** \ingroup libusb_desc
* Get the USB device descriptor for a given device.
*
@@ -516,7 +498,9 @@ int API_EXPORTED libusb_get_device_descriptor(libusb_device *dev,
struct libusb_device_descriptor *desc)
{
usbi_dbg(" ");
- memcpy(desc, &dev->device_descriptor, sizeof(dev->device_descriptor));
+ static_assert(sizeof(dev->device_descriptor) == LIBUSB_DT_DEVICE_SIZE,
+ "struct libusb_device_descriptor is not expected size");
+ *desc = dev->device_descriptor;
return 0;
}
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 88db762..88772e7 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -36,6 +36,13 @@
#include "libusb.h"
+/* Not all C standard library headers define static_assert in assert.h
+ * Additionally, Visual Studio treats static_assert as a keyword.
+ */
+#if !defined(__cplusplus) && !defined(static_assert) && !defined(_MSC_VER)
+#define static_assert(cond, msg) _Static_assert(cond, msg)
+#endif
+
#define container_of(ptr, type, member) \
((type *)((uintptr_t)(ptr) - (uintptr_t)offsetof(type, member)))
@@ -450,6 +457,17 @@ struct libusb_device_handle {
int auto_detach_kernel_driver;
};
+/* Function called by backend during device initialization to convert
+ * multi-byte fields in the device descriptor to host-endian format.
+ */
+static inline void usbi_localize_device_descriptor(struct libusb_device_descriptor *desc)
+{
+ desc->bcdUSB = libusb_le16_to_cpu(desc->bcdUSB);
+ desc->idVendor = libusb_le16_to_cpu(desc->idVendor);
+ desc->idProduct = libusb_le16_to_cpu(desc->idProduct);
+ desc->bcdDevice = libusb_le16_to_cpu(desc->bcdDevice);
+}
+
#ifdef HAVE_CLOCK_GETTIME
#define USBI_CLOCK_REALTIME CLOCK_REALTIME
#define USBI_CLOCK_MONOTONIC CLOCK_MONOTONIC
@@ -618,7 +636,6 @@ int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
int usbi_handle_transfer_cancellation(struct usbi_transfer *itransfer);
void usbi_signal_transfer_completion(struct usbi_transfer *itransfer);
-int usbi_device_cache_descriptor(libusb_device *dev);
int usbi_get_config_index_by_value(struct libusb_device *dev,
uint8_t bConfigurationValue, int *idx);
@@ -851,30 +868,6 @@ struct usbi_os_backend {
*/
void (*close)(struct libusb_device_handle *dev_handle);
- /* Retrieve the device descriptor from a device.
- *
- * The descriptor should be retrieved from memory, NOT via bus I/O to the
- * device. This means that you may have to cache it in a private structure
- * during get_device_list enumeration. Alternatively, you may be able
- * to retrieve it from a kernel interface (some Linux setups can do this)
- * still without generating bus I/O.
- *
- * This function is expected to write LIBUSB_DT_DEVICE_SIZE (18) bytes into
- * buffer, which is guaranteed to be big enough.
- *
- * This function is called when sanity-checking a device before adding
- * it to the list of discovered devices, and also when the user requests
- * to read the device descriptor.
- *
- * This function is expected to return the descriptor in bus-endian format
- * (LE). If it returns the multi-byte values in host-endian format,
- * set the host_endian output parameter to "1".
- *
- * Return 0 on success or a LIBUSB_ERROR code on failure.
- */
- int (*get_device_descriptor)(struct libusb_device *device, void *buffer,
- int *host_endian);
-
/* Get the ACTIVE configuration descriptor for a device.
*
* The descriptor should be retrieved from memory, NOT via bus I/O to the
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 61722c0..de5ce9c 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -661,15 +661,6 @@ static void darwin_exit (struct libusb_context *ctx) {
pthread_mutex_unlock (&libusb_darwin_init_mutex);
}
-static int darwin_get_device_descriptor(struct libusb_device *dev, void *buffer, int *host_endian) {
- struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
-
- /* return cached copy */
- memmove (buffer, &(priv->dev_descriptor), LIBUSB_DT_DEVICE_SIZE);
-
- return LIBUSB_SUCCESS;
-}
-
static int get_configuration_index (struct libusb_device *dev, int config_value) {
struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
UInt8 i, numConfig;
@@ -749,7 +740,8 @@ static enum libusb_error darwin_check_configuration (struct libusb_context *ctx,
/* checking the configuration of a root hub simulation takes ~1 s in 10.11. the device is
not usable anyway */
- if (0x05ac == dev->dev_descriptor.idVendor && 0x8005 == dev->dev_descriptor.idProduct) {
+ if (0x05ac == libusb_le16_to_cpu (dev->dev_descriptor.idVendor) &&
+ 0x8005 == libusb_le16_to_cpu (dev->dev_descriptor.idProduct)) {
usbi_dbg ("ignoring configuration on root hub simulation");
dev->active_config = 0;
return LIBUSB_SUCCESS;
@@ -930,14 +922,14 @@ static enum libusb_error darwin_cache_device_descriptor (struct darwin_cached_de
usbi_dbg ("cached device descriptor:");
usbi_dbg (" bDescriptorType: 0x%02x", dev->dev_descriptor.bDescriptorType);
- usbi_dbg (" bcdUSB: 0x%04x", dev->dev_descriptor.bcdUSB);
+ usbi_dbg (" bcdUSB: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.bcdUSB));
usbi_dbg (" bDeviceClass: 0x%02x", dev->dev_descriptor.bDeviceClass);
usbi_dbg (" bDeviceSubClass: 0x%02x", dev->dev_descriptor.bDeviceSubClass);
usbi_dbg (" bDeviceProtocol: 0x%02x", dev->dev_descriptor.bDeviceProtocol);
usbi_dbg (" bMaxPacketSize0: 0x%02x", dev->dev_descriptor.bMaxPacketSize0);
- usbi_dbg (" idVendor: 0x%04x", dev->dev_descriptor.idVendor);
- usbi_dbg (" idProduct: 0x%04x", dev->dev_descriptor.idProduct);
- usbi_dbg (" bcdDevice: 0x%04x", dev->dev_descriptor.bcdDevice);
+ usbi_dbg (" idVendor: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.idVendor));
+ usbi_dbg (" idProduct: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.idProduct));
+ usbi_dbg (" bcdDevice: 0x%04x", libusb_le16_to_cpu (dev->dev_descriptor.bcdDevice));
usbi_dbg (" iManufacturer: 0x%02x", dev->dev_descriptor.iManufacturer);
usbi_dbg (" iProduct: 0x%02x", dev->dev_descriptor.iProduct);
usbi_dbg (" iSerialNumber: 0x%02x", dev->dev_descriptor.iSerialNumber);
@@ -1074,7 +1066,8 @@ static enum libusb_error darwin_get_cached_device(io_service_t service, struct d
if (new_device->can_enumerate) {
snprintf(new_device->sys_path, 20, "%03i-%04x-%04x-%02x-%02x", new_device->address,
- new_device->dev_descriptor.idVendor, new_device->dev_descriptor.idProduct,
+ libusb_le16_to_cpu (new_device->dev_descriptor.idVendor),
+ libusb_le16_to_cpu (new_device->dev_descriptor.idProduct),
new_device->dev_descriptor.bDeviceClass, new_device->dev_descriptor.bDeviceSubClass);
}
} while (0);
@@ -1122,6 +1115,10 @@ static enum libusb_error process_new_device (struct libusb_context *ctx, struct
dev->bus_number = cached_device->location >> 24;
assert(cached_device->address <= UINT8_MAX);
dev->device_address = (uint8_t)cached_device->address;
+ static_assert(sizeof(dev->device_descriptor) == sizeof(cached_device->dev_descriptor),
+ "mismatch between libusb and IOKit device descriptor sizes");
+ memcpy(&dev->device_descriptor, &cached_device->dev_descriptor, LIBUSB_DT_DEVICE_SIZE);
+ usbi_localize_device_descriptor(&dev->device_descriptor);
} else {
priv = usbi_get_device_priv(dev);
}
@@ -2260,7 +2257,6 @@ const struct usbi_os_backend usbi_backend = {
.caps = 0,
.init = darwin_init,
.exit = darwin_exit,
- .get_device_descriptor = darwin_get_device_descriptor,
.get_active_config_descriptor = darwin_get_active_config_descriptor,
.get_config_descriptor = darwin_get_config_descriptor,
.hotplug_poll = darwin_hotplug_poll,
diff --git a/libusb/os/haiku_pollfs.cpp b/libusb/os/haiku_pollfs.cpp
index cb28c51..c60b3b5 100644
--- a/libusb/os/haiku_pollfs.cpp
+++ b/libusb/os/haiku_pollfs.cpp
@@ -128,6 +128,11 @@ WatchedEntry::WatchedEntry(BMessenger *messenger, entry_ref *ref)
sscanf(path.Path(), "/dev/bus/usb/%hhu", &dev->bus_number);
dev->device_address = addr - (dev->bus_number + 1);
+ static_assert(sizeof(dev->device_descriptor) == sizeof(usb_device_descriptor),
+ "mismatch between libusb and OS device descriptor sizes");
+ memcpy(&dev->device_descriptor, fDevice->Descriptor(), LIBUSB_DT_DEVICE_SIZE);
+ usbi_localize_device_descriptor(&dev->device_descriptor);
+
if (usbi_sanitize_device(dev) < 0) {
usbi_dbg("device sanitization failed");
libusb_unref_device(dev);
diff --git a/libusb/os/haiku_usb_raw.cpp b/libusb/os/haiku_usb_raw.cpp
index b4348e2..f48c507 100644
--- a/libusb/os/haiku_usb_raw.cpp
+++ b/libusb/os/haiku_usb_raw.cpp
@@ -75,14 +75,6 @@ haiku_close(struct libusb_device_handle *dev_handle)
}
static int
-haiku_get_device_descriptor(struct libusb_device *device, void *buffer, int *host_endian)
-{
- USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
- memcpy(buffer, dev->Descriptor(), LIBUSB_DT_DEVICE_SIZE);
- return LIBUSB_SUCCESS;
-}
-
-static int
haiku_get_active_config_descriptor(struct libusb_device *device, void *buffer, size_t len)
{
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
@@ -198,7 +190,6 @@ const struct usbi_os_backend usbi_backend = {
/*.open =*/ haiku_open,
/*.close =*/ haiku_close,
- /*.get_device_descriptor =*/ haiku_get_device_descriptor,
/*.get_active_config_descriptor =*/ haiku_get_active_config_descriptor,
/*.get_config_descriptor =*/ haiku_get_config_descriptor,
/*.get_config_descriptor_by_value =*/ NULL,
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index f5fbee1..cfa9402 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -516,17 +516,6 @@ static int read_sysfs_attr(struct libusb_context *ctx,
return 0;
}
-static int op_get_device_descriptor(struct libusb_device *dev,
- void *buffer, int *host_endian)
-{
- struct linux_device_priv *priv = usbi_get_device_priv(dev);
-
- *host_endian = priv->sysfs_dir != NULL;
- memcpy(buffer, priv->descriptors, LIBUSB_DT_DEVICE_SIZE);
-
- return 0;
-}
-
static int sysfs_scan_device(struct libusb_context *ctx, const char *devname)
{
uint8_t busnum, devaddr;
@@ -899,8 +888,13 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
return LIBUSB_ERROR_IO;
}
- if (sysfs_dir)
+ memcpy(&dev->device_descriptor, priv->descriptors, LIBUSB_DT_DEVICE_SIZE);
+
+ if (sysfs_dir) {
+ /* sysfs descriptors are in bus-endian format */
+ usbi_localize_device_descriptor(&dev->device_descriptor);
return LIBUSB_SUCCESS;
+ }
/* cache active config */
if (wrapped_fd < 0)
@@ -2664,7 +2658,6 @@ const struct usbi_os_backend usbi_backend = {
.init = op_init,
.exit = op_exit,
.hotplug_poll = op_hotplug_poll,
- .get_device_descriptor = op_get_device_descriptor,
.get_active_config_descriptor = op_get_active_config_descriptor,
.get_config_descriptor = op_get_config_descriptor,
.get_config_descriptor_by_value = op_get_config_descriptor_by_value,
diff --git a/libusb/os/netbsd_usb.c b/libusb/os/netbsd_usb.c
index 91f2472..485208d 100644
--- a/libusb/os/netbsd_usb.c
+++ b/libusb/os/netbsd_usb.c
@@ -37,7 +37,6 @@ struct device_priv {
int fd;
usb_config_descriptor_t *cdesc; /* active config descriptor */
- usb_device_descriptor_t ddesc; /* usb device descriptor */
};
struct handle_priv {
@@ -52,8 +51,6 @@ static int netbsd_get_device_list(struct libusb_context *,
static int netbsd_open(struct libusb_device_handle *);
static void netbsd_close(struct libusb_device_handle *);
-static int netbsd_get_device_descriptor(struct libusb_device *, void *,
- int *);
static int netbsd_get_active_config_descriptor(struct libusb_device *,
void *, size_t);
static int netbsd_get_config_descriptor(struct libusb_device *, uint8_t,
@@ -90,7 +87,6 @@ const struct usbi_os_backend usbi_backend = {
.open = netbsd_open,
.close = netbsd_close,
- .get_device_descriptor = netbsd_get_device_descriptor,
.get_active_config_descriptor = netbsd_get_active_config_descriptor,
.get_config_descriptor = netbsd_get_config_descriptor,
@@ -121,6 +117,7 @@ netbsd_get_device_list(struct libusb_context * ctx,
struct libusb_device *dev;
struct device_priv *dpriv;
struct usb_device_info di;
+ usb_device_descriptor_t ddesc;
unsigned long session_id;
char devnode[16];
int fd, err, i;
@@ -157,11 +154,16 @@ netbsd_get_device_list(struct libusb_context * ctx,
strlcpy(dpriv->devnode, devnode, sizeof(devnode));
dpriv->fd = -1;
- if (ioctl(fd, USB_GET_DEVICE_DESC, &dpriv->ddesc) < 0) {
+ if (ioctl(fd, USB_GET_DEVICE_DESC, &ddesc) < 0) {
err = errno;
goto error;
}
+ static_assert(sizeof(dev->device_descriptor) == sizeof(ddesc),
+ "mismatch between libusb and OS device descriptor sizes");
+ memcpy(&dev->device_descriptor, &ddesc, LIBUSB_DT_DEVICE_SIZE);
+ usbi_localize_device_descriptor(&dev->device_descriptor);
+
if (_cache_active_config_descriptor(dev, fd)) {
err = errno;
goto error;
@@ -220,19 +222,6 @@ netbsd_close(struct libusb_device_handle *handle)
}
int
-netbsd_get_device_descriptor(struct libusb_device *dev, void *buf,
- int *host_endian)
-{
- struct device_priv *dpriv = usbi_get_device_priv(dev);
-
- usbi_dbg(" ");
-
- memcpy(buf, &dpriv->ddesc, LIBUSB_DT_DEVICE_SIZE);
-
- return (LIBUSB_SUCCESS);
-}
-
-int
netbsd_get_active_config_descriptor(struct libusb_device *dev,
void *buf, size_t len)
{
diff --git a/libusb/os/null_usb.c b/libusb/os/null_usb.c
index 8952f3b..06278b1 100644
--- a/libusb/os/null_usb.c
+++ b/libusb/os/null_usb.c
@@ -37,13 +37,6 @@ null_close(struct libusb_device_handle *handle)
}
static int
-null_get_device_descriptor(struct libusb_device *dev, void *buf,
- int *host_endian)
-{
- return LIBUSB_ERROR_NOT_SUPPORTED;
-}
-
-static int
null_get_active_config_descriptor(struct libusb_device *dev,
void *buf, size_t len)
{
@@ -106,7 +99,6 @@ const struct usbi_os_backend usbi_backend = {
.get_device_list = null_get_device_list,
.open = null_open,
.close = null_close,
- .get_device_descriptor = null_get_device_descriptor,
.get_active_config_descriptor = null_get_active_config_descriptor,
.get_config_descriptor = null_get_config_descriptor,
.set_configuration = null_set_configuration,
diff --git a/libusb/os/openbsd_usb.c b/libusb/os/openbsd_usb.c
index 8f9c4e7..41550b0 100644
--- a/libusb/os/openbsd_usb.c
+++ b/libusb/os/openbsd_usb.c
@@ -37,7 +37,6 @@ struct device_priv {
int fd; /* device file descriptor */
usb_config_descriptor_t *cdesc; /* active config descriptor */
- usb_device_descriptor_t ddesc; /* usb device descriptor */
};
struct handle_priv {
@@ -52,8 +51,6 @@ static int obsd_get_device_list(struct libusb_context *,
static int obsd_open(struct libusb_device_handle *);
static void obsd_close(struct libusb_device_handle *);
-static int obsd_get_device_descriptor(struct libusb_device *, void *,
- int *);
static int obsd_get_active_config_descriptor(struct libusb_device *,
void *, size_t);
static int obsd_get_config_descriptor(struct libusb_device *, uint8_t,
@@ -92,7 +89,6 @@ const struct usbi_os_backend usbi_backend = {
.open = obsd_open,
.close = obsd_close,
- .get_device_descriptor = obsd_get_device_descriptor,
.get_active_config_descriptor = obsd_get_active_config_descriptor,
.get_config_descriptor = obsd_get_config_descriptor,
@@ -188,7 +184,11 @@ obsd_get_device_list(struct libusb_context * ctx,
libusb_unref_device(dev);
continue;
}
- dpriv->ddesc = dd.udd_desc;
+
+ static_assert(sizeof(dev->device_descriptor) == sizeof(dd.udd_desc),
+ "mismatch between libusb and OS device descriptor sizes");
+ memcpy(&dev->device_descriptor, &dd.udd_desc, LIBUSB_DT_DEVICE_SIZE);
+ usbi_localize_device_descriptor(&dev->device_descriptor);
if (_cache_active_config_descriptor(dev)) {
libusb_unref_device(dev);
@@ -255,19 +255,6 @@ obsd_close(struct libusb_device_handle *handle)
}
int
-obsd_get_device_descriptor(struct libusb_device *dev, void *buf,
- int *host_endian)
-{
- struct device_priv *dpriv = usbi_get_device_priv(dev);
-
- usbi_dbg(" ");
-
- memcpy(buf, &dpriv->ddesc, LIBUSB_DT_DEVICE_SIZE);
-
- return (LIBUSB_SUCCESS);
-}
-
-int
obsd_get_active_config_descriptor(struct libusb_device *dev,
void *buf, size_t len)
{
diff --git a/libusb/os/sunos_usb.c b/libusb/os/sunos_usb.c
index 31857b4..5ca29f5 100644
--- a/libusb/os/sunos_usb.c
+++ b/libusb/os/sunos_usb.c
@@ -62,8 +62,6 @@ static int sunos_get_device_list(struct libusb_context *,
struct discovered_devs **);
static int sunos_open(struct libusb_device_handle *);
static void sunos_close(struct libusb_device_handle *);
-static int sunos_get_device_descriptor(struct libusb_device *,
- void *, int *);
static int sunos_get_active_config_descriptor(struct libusb_device *,
void *, size_t);
static int sunos_get_config_descriptor(struct libusb_device *, uint8_t,
@@ -389,8 +387,8 @@ sunos_detach_kernel_driver(struct libusb_device_handle *dev_handle,
usbi_warn(HANDLE_CTX(dev_handle), "one or more ioctls failed");
snprintf(path_arg, sizeof(path_arg), "^usb/%x.%x",
- libusb_le16_to_cpu(dpriv->dev_descr.idVendor),
- libusb_le16_to_cpu(dpriv->dev_descr.idProduct));
+ dev_handle->dev->device_descriptor.idVendor,
+ dev_handle->dev->device_descriptor.idProduct);
sunos_physpath_to_devlink(dpriv->phypath, path_arg, &dpriv->ugenpath);
if (access(dpriv->ugenpath, F_OK) == -1) {
@@ -457,7 +455,6 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
int *i, n, *addr, *port_prop;
char *phypath;
uint8_t *rdata;
- struct libusb_device_descriptor *descr;
sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
char match_str[PATH_MAX];
@@ -465,16 +462,9 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
"usb-dev-descriptor", &rdata);
if (proplen <= 0) {
-
return (LIBUSB_ERROR_IO);
}
-
- descr = (struct libusb_device_descriptor *)rdata;
- bcopy(descr, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
- dpriv->dev_descr.bcdUSB = libusb_cpu_to_le16(descr->bcdUSB);
- dpriv->dev_descr.idVendor = libusb_cpu_to_le16(descr->idVendor);
- dpriv->dev_descr.idProduct = libusb_cpu_to_le16(descr->idProduct);
- dpriv->dev_descr.bcdDevice = libusb_cpu_to_le16(descr->bcdDevice);
+ bcopy(rdata, &dev->device_descriptor, LIBUSB_DT_DEVICE_SIZE);
/* Raw configuration descriptors */
proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
@@ -505,8 +495,8 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
if (phypath) {
dpriv->phypath = strdup(phypath);
snprintf(match_str, sizeof(match_str), "^usb/%x.%x",
- libusb_le16_to_cpu(dpriv->dev_descr.idVendor),
- libusb_le16_to_cpu(dpriv->dev_descr.idProduct));
+ dev->device_descriptor.idVendor,
+ dev->device_descriptor.idProduct);
usbi_dbg("match is %s", match_str);
sunos_physpath_to_devlink(dpriv->phypath, match_str, &dpriv->ugenpath);
di_devfs_path_free(phypath);
@@ -536,10 +526,8 @@ sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
dev->speed = LIBUSB_SPEED_SUPER;
}
- usbi_dbg("vid=%x pid=%x, path=%s, bus_nmber=0x%x, port_number=%d, "
- "speed=%d",
- libusb_le16_to_cpu(dpriv->dev_descr.idVendor),
- libusb_le16_to_cpu(dpriv->dev_descr.idProduct),
+ usbi_dbg("vid=%x pid=%x, path=%s, bus_nmber=0x%x, port_number=%d, speed=%d",
+ dev->device_descriptor.idVendor, dev->device_descriptor.idProduct,
dpriv->phypath, dev->bus_number, dev->port_number, dev->speed);
return (LIBUSB_SUCCESS);
@@ -1020,17 +1008,6 @@ sunos_close(struct libusb_device_handle *handle)
}
int
-sunos_get_device_descriptor(struct libusb_device *dev, void *buf,
- int *host_endian)
-{
- sunos_dev_priv_t *dpriv = usbi_get_device_priv(dev);
-
- memcpy(buf, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
-
- return (LIBUSB_SUCCESS);
-}
-
-int
sunos_get_active_config_descriptor(struct libusb_device *dev,
void *buf, size_t len)
{
@@ -1610,7 +1587,6 @@ const struct usbi_os_backend usbi_backend = {
.name = "Solaris",
.caps = 0,
.get_device_list = sunos_get_device_list,
- .get_device_descriptor = sunos_get_device_descriptor,
.get_active_config_descriptor = sunos_get_active_config_descriptor,
.get_config_descriptor = sunos_get_config_descriptor,
.open = sunos_open,
diff --git a/libusb/os/sunos_usb.h b/libusb/os/sunos_usb.h
index 52bb3d3..2988398 100644
--- a/libusb/os/sunos_usb.h
+++ b/libusb/os/sunos_usb.h
@@ -30,7 +30,6 @@
typedef struct sunos_device_priv {
uint8_t cfgvalue; /* active config value */
uint8_t *raw_cfgdescr; /* active config descriptor */
- struct libusb_device_descriptor dev_descr; /* usb device descriptor */
char *ugenpath; /* name of the ugen(4) node */
char *phypath; /* physical path */
} sunos_dev_priv_t;
diff --git a/libusb/os/windows_common.c b/libusb/os/windows_common.c
index 9352091..1c1ca01 100644
--- a/libusb/os/windows_common.c
+++ b/libusb/os/windows_common.c
@@ -598,13 +598,6 @@ static void windows_close(struct libusb_device_handle *dev_handle)
priv->backend->close(dev_handle);
}
-static int windows_get_device_descriptor(struct libusb_device *dev,
- void *buffer, int *host_endian)
-{
- struct windows_context_priv *priv = usbi_get_context_priv(DEVICE_CTX(dev));
- return priv->backend->get_device_descriptor(dev, buffer);
-}
-
static int windows_get_active_config_descriptor(struct libusb_device *dev,
void *buffer, size_t len)
{
@@ -868,7 +861,6 @@ const struct usbi_os_backend usbi_backend = {
NULL, /* wrap_sys_device */
windows_open,
windows_close,
- windows_get_device_descriptor,
windows_get_active_config_descriptor,
windows_get_config_descriptor,
windows_get_config_descriptor_by_value,
diff --git a/libusb/os/windows_common.h b/libusb/os/windows_common.h
index e48f7a9..6617de4 100644
--- a/libusb/os/windows_common.h
+++ b/libusb/os/windows_common.h
@@ -224,7 +224,7 @@ typedef struct USB_DK_TRANSFER_REQUEST {
} USB_DK_TRANSFER_REQUEST, *PUSB_DK_TRANSFER_REQUEST;
struct usbdk_device_priv {
- USB_DK_DEVICE_INFO info;
+ USB_DK_DEVICE_ID ID;
PUSB_CONFIGURATION_DESCRIPTOR *config_descriptors;
HANDLE redirector_handle;
HANDLE system_handle;
@@ -251,7 +251,6 @@ struct winusb_device_priv {
// by Windows (eg. HID keyboards or mice cannot do R/W)
} usb_interface[USB_MAXINTERFACES];
struct hid_device_priv *hid;
- USB_DEVICE_DESCRIPTOR dev_descriptor;
PUSB_CONFIGURATION_DESCRIPTOR *config_descriptor; // list of pointers to the cached config descriptors
};
@@ -299,7 +298,6 @@ struct windows_backend {
struct discovered_devs **discdevs);
int (*open)(struct libusb_device_handle *dev_handle);
void (*close)(struct libusb_device_handle *dev_handle);
- int (*get_device_descriptor)(struct libusb_device *device, void *buffer);
int (*get_active_config_descriptor)(struct libusb_device *device,
void *buffer, size_t len);
int (*get_config_descriptor)(struct libusb_device *device,
diff --git a/libusb/os/windows_usbdk.c b/libusb/os/windows_usbdk.c
index 15783b0..7d6a3d5 100644
--- a/libusb/os/windows_usbdk.c
+++ b/libusb/os/windows_usbdk.c
@@ -271,13 +271,13 @@ static inline int usbdk_device_priv_init(struct libusb_context *ctx, struct libu
{
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
- priv->info = *info;
+ priv->ID = info->ID;
priv->active_configuration = 0;
return usbdk_cache_config_descriptors(ctx, priv, info);
}
-static void usbdk_device_init(libusb_device *dev, PUSB_DK_DEVICE_INFO info)
+static void usbdk_device_init(struct libusb_device *dev, PUSB_DK_DEVICE_INFO info)
{
dev->bus_number = (uint8_t)info->FilterID;
dev->port_number = (uint8_t)info->Port;
@@ -286,7 +286,10 @@ static void usbdk_device_init(libusb_device *dev, PUSB_DK_DEVICE_INFO info)
// Addresses in libusb are 1-based
dev->device_address = (uint8_t)(info->Port + 1);
+ static_assert(sizeof(dev->device_descriptor) == sizeof(info->DeviceDescriptor),
+ "mismatch between libusb and OS device descriptor sizes");
memcpy(&dev->device_descriptor, &info->DeviceDescriptor, LIBUSB_DT_DEVICE_SIZE);
+ usbi_localize_device_descriptor(&dev->device_descriptor);
switch (info->Speed) {
case LowSpeed:
@@ -357,15 +360,6 @@ func_exit:
return r;
}
-static int usbdk_get_device_descriptor(struct libusb_device *dev, void *buffer)
-{
- struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
-
- memcpy(buffer, &priv->info.DeviceDescriptor, LIBUSB_DT_DEVICE_SIZE);
-
- return LIBUSB_SUCCESS;
-}
-
static int usbdk_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, void *buffer, size_t len)
{
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
@@ -408,7 +402,7 @@ static int usbdk_open(struct libusb_device_handle *dev_handle)
{
struct usbdk_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
- priv->redirector_handle = usbdk_helper.StartRedirect(&priv->info.ID);
+ priv->redirector_handle = usbdk_helper.StartRedirect(&priv->ID);
if (priv->redirector_handle == INVALID_HANDLE_VALUE) {
usbi_err(HANDLE_CTX(dev_handle), "Redirector startup failed");
return LIBUSB_ERROR_OTHER;
@@ -498,7 +492,7 @@ static void usbdk_destroy_device(struct libusb_device *dev)
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
if (priv->config_descriptors != NULL)
- usbdk_release_config_descriptors(priv, priv->info.DeviceDescriptor.bNumConfigurations);
+ usbdk_release_config_descriptors(priv, dev->device_descriptor.bNumConfigurations);
}
static void usbdk_clear_transfer_priv(struct usbi_transfer *itransfer)
@@ -698,7 +692,6 @@ const struct windows_backend usbdk_backend = {
usbdk_get_device_list,
usbdk_open,
usbdk_close,
- usbdk_get_device_descriptor,
usbdk_get_active_config_descriptor,
usbdk_get_config_descriptor,
usbdk_get_config_descriptor_by_value,
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index d2e3893..a623a61 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -674,7 +674,7 @@ static void cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handl
PUSB_DESCRIPTOR_REQUEST cd_buf_actual = NULL; // actual request
PUSB_CONFIGURATION_DESCRIPTOR cd_data;
- num_configurations = priv->dev_descriptor.bNumConfigurations;
+ num_configurations = dev->device_descriptor.bNumConfigurations;
if (num_configurations == 0)
return;
@@ -847,13 +847,17 @@ static int init_device(struct libusb_device *dev, struct libusb_device *parent_d
return LIBUSB_ERROR_NO_DEVICE;
}
- memcpy(&priv->dev_descriptor, &(conn_info.DeviceDescriptor), sizeof(USB_DEVICE_DESCRIPTOR));
+ static_assert(sizeof(dev->device_descriptor) == sizeof(conn_info.DeviceDescriptor),
+ "mismatch between libusb and OS device descriptor sizes");
+ memcpy(&dev->device_descriptor, &conn_info.DeviceDescriptor, LIBUSB_DT_DEVICE_SIZE);
+ usbi_localize_device_descriptor(&dev->device_descriptor);
+
priv->active_config = conn_info.CurrentConfigurationValue;
if (priv->active_config == 0) {
usbi_dbg("0x%x:0x%x found %u configurations (not configured)",
- priv->dev_descriptor.idVendor,
- priv->dev_descriptor.idProduct,
- priv->dev_descriptor.bNumConfigurations);
+ dev->device_descriptor.idVendor,
+ dev->device_descriptor.idProduct,
+ dev->device_descriptor.bNumConfigurations);
SleepEx(50, TRUE);
}
} while (priv->active_config == 0 && --ginfotimeout >= 0);
@@ -861,12 +865,12 @@ static int init_device(struct libusb_device *dev, struct libusb_device *parent_d
if (priv->active_config == 0) {
usbi_info(ctx, "0x%x:0x%x found %u configurations but device isn't configured, "
"forcing current configuration to 1",
- priv->dev_descriptor.idVendor,
- priv->dev_descriptor.idProduct,
- priv->dev_descriptor.bNumConfigurations);
+ dev->device_descriptor.idVendor,
+ dev->device_descriptor.idProduct,
+ dev->device_descriptor.bNumConfigurations);
priv->active_config = 1;
} else {
- usbi_dbg("found %u configurations (current config: %u)", priv->dev_descriptor.bNumConfigurations, priv->active_config);
+ usbi_dbg("found %u configurations (current config: %u)", dev->device_descriptor.bNumConfigurations, priv->active_config);
}
// Cache as many config descriptors as we can
@@ -944,16 +948,16 @@ static int enumerate_hcd_root_hub(struct libusb_context *ctx, const char *dev_id
usbi_dbg("assigning HCD '%s' bus number %u", dev_id, bus_number);
priv = usbi_get_device_priv(dev);
dev->bus_number = bus_number;
- priv->dev_descriptor.bLength = LIBUSB_DT_DEVICE_SIZE;
- priv->dev_descriptor.bDescriptorType = LIBUSB_DT_DEVICE;
- priv->dev_descriptor.bDeviceClass = LIBUSB_CLASS_HUB;
- priv->dev_descriptor.bNumConfigurations = 1;
+ dev->device_descriptor.bLength = LIBUSB_DT_DEVICE_SIZE;
+ dev->device_descriptor.bDescriptorType = LIBUSB_DT_DEVICE;
+ dev->device_descriptor.bDeviceClass = LIBUSB_CLASS_HUB;
+ dev->device_descriptor.bNumConfigurations = 1;
priv->active_config = 1;
priv->root_hub = true;
- if (sscanf(dev_id, "PCI\\VEN_%04hx&DEV_%04hx%*s", &priv->dev_descriptor.idVendor, &priv->dev_descriptor.idProduct) != 2) {
+ if (sscanf(dev_id, "PCI\\VEN_%04hx&DEV_%04hx%*s", &dev->device_descriptor.idVendor, &dev->device_descriptor.idProduct) != 2) {
usbi_warn(ctx, "could not infer VID/PID of HCD root hub from '%s'", dev_id);
- priv->dev_descriptor.idVendor = 0x1d6b; // Linux Foundation root hub
- priv->dev_descriptor.idProduct = 1;
+ dev->device_descriptor.idVendor = 0x1d6b; // Linux Foundation root hub
+ dev->device_descriptor.idProduct = 1;
}
}
@@ -1515,14 +1519,6 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_
return r;
}
-static int winusb_get_device_descriptor(struct libusb_device *dev, void *buffer)
-{
- struct winusb_device_priv *priv = usbi_get_device_priv(dev);
-
- memcpy(buffer, &priv->dev_descriptor, LIBUSB_DT_DEVICE_SIZE);
- return LIBUSB_SUCCESS;
-}
-
static int winusb_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, void *buffer, size_t len)
{
struct winusb_device_priv *priv = usbi_get_device_priv(dev);
@@ -1792,7 +1788,6 @@ const struct windows_backend winusb_backend = {
winusb_get_device_list,
winusb_open,
winusb_close,
- winusb_get_device_descriptor,
winusb_get_active_config_descriptor,
winusb_get_config_descriptor,
winusb_get_config_descriptor_by_value,
@@ -3383,7 +3378,8 @@ static void hid_exit(void)
// composite_open(), with interfaces belonging to different APIs
static int hid_open(int sub_api, struct libusb_device_handle *dev_handle)
{
- struct winusb_device_priv *priv = usbi_get_device_priv(dev_handle->dev);
+ struct libusb_device *dev = dev_handle->dev;
+ struct winusb_device_priv *priv = usbi_get_device_priv(dev);
struct winusb_device_handle_priv *handle_priv = usbi_get_device_handle_priv(dev_handle);
HIDD_ATTRIBUTES hid_attributes;
PHIDP_PREPARSED_DATA preparsed_data = NULL;
@@ -3507,19 +3503,19 @@ static int hid_open(int sub_api, struct libusb_device_handle *dev_handle)
priv->hid->usagePage = capabilities.UsagePage;
// Fetch string descriptors
- priv->hid->string_index[0] = priv->dev_descriptor.iManufacturer;
+ priv->hid->string_index[0] = dev->device_descriptor.iManufacturer;
if (priv->hid->string_index[0] != 0)
HidD_GetManufacturerString(hid_handle, priv->hid->string[0], sizeof(priv->hid->string[0]));
else
priv->hid->string[0][0] = 0;
- priv->hid->string_index[1] = priv->dev_descriptor.iProduct;
+ priv->hid->string_index[1] = dev->device_descriptor.iProduct;
if (priv->hid->string_index[1] != 0)
HidD_GetProductString(hid_handle, priv->hid->string[1], sizeof(priv->hid->string[1]));
else
priv->hid->string[1][0] = 0;
- priv->hid->string_index[2] = priv->dev_descriptor.iSerialNumber;
+ priv->hid->string_index[2] = dev->device_descriptor.iSerialNumber;
if (priv->hid->string_index[2] != 0)
HidD_GetSerialNumberString(hid_handle, priv->hid->string[2], sizeof(priv->hid->string[2]));
else
diff --git a/libusb/os/windows_winusb.h b/libusb/os/windows_winusb.h
index ef667bd..39ce6fe 100644
--- a/libusb/os/windows_winusb.h
+++ b/libusb/os/windows_winusb.h
@@ -220,8 +220,8 @@ static inline void winusb_device_priv_release(struct libusb_device *dev)
free(priv->dev_id);
free(priv->path);
- if ((priv->dev_descriptor.bNumConfigurations > 0) && (priv->config_descriptor != NULL)) {
- for (i = 0; i < priv->dev_descriptor.bNumConfigurations; i++) {
+ if ((dev->device_descriptor.bNumConfigurations > 0) && (priv->config_descriptor != NULL)) {
+ for (i = 0; i < dev->device_descriptor.bNumConfigurations; i++) {
if (priv->config_descriptor[i] == NULL)
continue;
free((UCHAR *)priv->config_descriptor[i] - USB_DESCRIPTOR_REQUEST_SIZE);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index c00f71a..51e1070 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11509
+#define LIBUSB_NANO 11510