summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-04-17 12:21:46 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2020-04-17 12:21:46 -0700
commite1fcd8ac57b709f775b1e7b57262408e94cfa5d5 (patch)
tree470976a3bb499b4d73a7323b959695e3db506909
parentf07af6458f9eb9b932112d12840039e321dac500 (diff)
downloadlibusb-e1fcd8ac57b709f775b1e7b57262408e94cfa5d5.tar.gz
core: Remove redundant definitions for descriptor sizes
The public libusb header provides all the definitions for the various descriptor sizes, so use them instead of defining them again with different names. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--libusb/descriptor.c15
-rw-r--r--libusb/libusbi.h4
-rw-r--r--libusb/os/darwin_usb.c2
-rw-r--r--libusb/os/haiku_usb_raw.cpp2
-rw-r--r--libusb/os/linux_usbfs.c16
-rw-r--r--libusb/os/netbsd_usb.c2
-rw-r--r--libusb/os/openbsd_usb.c2
-rw-r--r--libusb/os/windows_usbdk.c2
-rw-r--r--libusb/os/windows_winusb.c2
-rw-r--r--libusb/version_nano.h2
10 files changed, 21 insertions, 28 deletions
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 4e38f0f..95a6cd7 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -23,12 +23,7 @@
#include <string.h>
-#define DESC_HEADER_LENGTH 2
-#define DEVICE_DESC_LENGTH 18
-#define CONFIG_DESC_LENGTH 9
-#define INTERFACE_DESC_LENGTH 9
-#define ENDPOINT_DESC_LENGTH 7
-#define ENDPOINT_AUDIO_DESC_LENGTH 9
+#define DESC_HEADER_LENGTH 2
/** @defgroup libusb_desc USB descriptors
* This page details how to examine the various standard USB descriptors
@@ -116,9 +111,9 @@ static int parse_endpoint(struct libusb_context *ctx,
size, header->bLength);
return parsed;
}
- if (header->bLength >= ENDPOINT_AUDIO_DESC_LENGTH)
+ if (header->bLength >= LIBUSB_DT_ENDPOINT_AUDIO_SIZE)
parse_descriptor(buffer, "bbbbwbbb", endpoint, host_endian);
- else if (header->bLength >= ENDPOINT_DESC_LENGTH)
+ else if (header->bLength >= LIBUSB_DT_ENDPOINT_SIZE)
parse_descriptor(buffer, "bbbbwb", endpoint, host_endian);
else {
usbi_err(ctx, "invalid endpoint bLength (%d)", header->bLength);
@@ -217,7 +212,7 @@ static int parse_interface(libusb_context *ctx,
usb_interface->num_altsetting = 0;
- while (size >= INTERFACE_DESC_LENGTH) {
+ while (size >= LIBUSB_DT_INTERFACE_SIZE) {
struct libusb_interface_descriptor *altsetting =
(struct libusb_interface_descriptor *) usb_interface->altsetting;
altsetting = usbi_reallocf(altsetting,
@@ -236,7 +231,7 @@ static int parse_interface(libusb_context *ctx,
ifp->bDescriptorType, LIBUSB_DT_INTERFACE);
return parsed;
}
- if (ifp->bLength < INTERFACE_DESC_LENGTH) {
+ if (ifp->bLength < LIBUSB_DT_INTERFACE_SIZE) {
usbi_err(ctx, "invalid interface bLength (%d)",
ifp->bLength);
r = LIBUSB_ERROR_IO;
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index db9c919..a0bb1b4 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -104,8 +104,6 @@
extern "C" {
#endif
-#define DEVICE_DESC_LENGTH 18
-
#define USB_MAXENDPOINTS 32
#define USB_MAXINTERFACES 32
#define USB_MAXCONFIG 8
@@ -861,7 +859,7 @@ struct usbi_os_backend {
* 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 DEVICE_DESC_LENGTH (18) bytes into
+ * 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
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 4639a7e..9c639c1 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -665,7 +665,7 @@ static int darwin_get_device_descriptor(struct libusb_device *dev, unsigned char
struct darwin_cached_device *priv = DARWIN_CACHED_DEVICE(dev);
/* return cached copy */
- memmove (buffer, &(priv->dev_descriptor), DEVICE_DESC_LENGTH);
+ memmove (buffer, &(priv->dev_descriptor), LIBUSB_DT_DEVICE_SIZE);
*host_endian = 0;
diff --git a/libusb/os/haiku_usb_raw.cpp b/libusb/os/haiku_usb_raw.cpp
index af28c0b..087b227 100644
--- a/libusb/os/haiku_usb_raw.cpp
+++ b/libusb/os/haiku_usb_raw.cpp
@@ -78,7 +78,7 @@ static int
haiku_get_device_descriptor(struct libusb_device *device, unsigned char *buffer, int *host_endian)
{
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
- memcpy(buffer, dev->Descriptor(), DEVICE_DESC_LENGTH);
+ memcpy(buffer, dev->Descriptor(), LIBUSB_DT_DEVICE_SIZE);
*host_endian = 0;
return LIBUSB_SUCCESS;
}
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 4dd5337..a1662e4 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -522,7 +522,7 @@ static int op_get_device_descriptor(struct libusb_device *dev,
struct linux_device_priv *priv = usbi_get_device_priv(dev);
*host_endian = priv->sysfs_dir != NULL;
- memcpy(buffer, priv->descriptors, DEVICE_DESC_LENGTH);
+ memcpy(buffer, priv->descriptors, LIBUSB_DT_DEVICE_SIZE);
return 0;
}
@@ -706,8 +706,8 @@ static int op_get_config_descriptor_by_value(struct libusb_device *dev,
*host_endian = 0;
/* Skip device header */
- descriptors += DEVICE_DESC_LENGTH;
- size -= DEVICE_DESC_LENGTH;
+ descriptors += LIBUSB_DT_DEVICE_SIZE;
+ size -= LIBUSB_DT_DEVICE_SIZE;
/* Seek till the config is found, or till "EOF" */
while (1) {
@@ -764,8 +764,8 @@ static int op_get_config_descriptor(struct libusb_device *dev,
*host_endian = 0;
/* Skip device header */
- descriptors += DEVICE_DESC_LENGTH;
- size -= DEVICE_DESC_LENGTH;
+ descriptors += LIBUSB_DT_DEVICE_SIZE;
+ size -= LIBUSB_DT_DEVICE_SIZE;
/* Seek till the config is found, or till "EOF" */
for (i = 0; ; i++) {
@@ -900,7 +900,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
if (fd != wrapped_fd)
close(fd);
- if (priv->descriptors_len < DEVICE_DESC_LENGTH) {
+ if (priv->descriptors_len < LIBUSB_DT_DEVICE_SIZE) {
usbi_err(ctx, "short descriptor read (%d)", priv->descriptors_len);
return LIBUSB_ERROR_IO;
}
@@ -918,10 +918,10 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
* config. just assume the first one is active. */
usbi_warn(ctx, "Missing rw usbfs access; cannot determine "
"active configuration descriptor");
- if (priv->descriptors_len >= (DEVICE_DESC_LENGTH + LIBUSB_DT_CONFIG_SIZE)) {
+ if (priv->descriptors_len >= (LIBUSB_DT_DEVICE_SIZE + LIBUSB_DT_CONFIG_SIZE)) {
struct usbi_configuration_descriptor *config;
- config = (struct usbi_configuration_descriptor *)(priv->descriptors + DEVICE_DESC_LENGTH);
+ config = (struct usbi_configuration_descriptor *)(priv->descriptors + LIBUSB_DT_DEVICE_SIZE);
priv->active_config = config->bConfigurationValue;
} else {
priv->active_config = -1; /* No config dt */
diff --git a/libusb/os/netbsd_usb.c b/libusb/os/netbsd_usb.c
index 3255cf2..49f4439 100644
--- a/libusb/os/netbsd_usb.c
+++ b/libusb/os/netbsd_usb.c
@@ -228,7 +228,7 @@ netbsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
usbi_dbg(" ");
- memcpy(buf, &dpriv->ddesc, DEVICE_DESC_LENGTH);
+ memcpy(buf, &dpriv->ddesc, LIBUSB_DT_DEVICE_SIZE);
*host_endian = 0;
diff --git a/libusb/os/openbsd_usb.c b/libusb/os/openbsd_usb.c
index 1080026..55db699 100644
--- a/libusb/os/openbsd_usb.c
+++ b/libusb/os/openbsd_usb.c
@@ -263,7 +263,7 @@ obsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
usbi_dbg(" ");
- memcpy(buf, &dpriv->ddesc, DEVICE_DESC_LENGTH);
+ memcpy(buf, &dpriv->ddesc, LIBUSB_DT_DEVICE_SIZE);
*host_endian = 0;
diff --git a/libusb/os/windows_usbdk.c b/libusb/os/windows_usbdk.c
index bb370ca..ac11496 100644
--- a/libusb/os/windows_usbdk.c
+++ b/libusb/os/windows_usbdk.c
@@ -361,7 +361,7 @@ static int usbdk_get_device_descriptor(struct libusb_device *dev, unsigned char
{
struct usbdk_device_priv *priv = usbi_get_device_priv(dev);
- memcpy(buffer, &priv->info.DeviceDescriptor, DEVICE_DESC_LENGTH);
+ memcpy(buffer, &priv->info.DeviceDescriptor, LIBUSB_DT_DEVICE_SIZE);
return LIBUSB_SUCCESS;
}
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index 9c19ccc..ec7c025 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -1519,7 +1519,7 @@ static int winusb_get_device_descriptor(struct libusb_device *dev, unsigned char
{
struct winusb_device_priv *priv = usbi_get_device_priv(dev);
- memcpy(buffer, &priv->dev_descriptor, DEVICE_DESC_LENGTH);
+ memcpy(buffer, &priv->dev_descriptor, LIBUSB_DT_DEVICE_SIZE);
return LIBUSB_SUCCESS;
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 5454846..88eb388 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11504
+#define LIBUSB_NANO 11505