core: Remove redundant definitions for descriptor sizes
authorChris Dickens <christopher.a.dickens@gmail.com>
Fri, 17 Apr 2020 19:21:46 +0000 (12:21 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Fri, 17 Apr 2020 19:21:46 +0000 (12:21 -0700)
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>
libusb/descriptor.c
libusb/libusbi.h
libusb/os/darwin_usb.c
libusb/os/haiku_usb_raw.cpp
libusb/os/linux_usbfs.c
libusb/os/netbsd_usb.c
libusb/os/openbsd_usb.c
libusb/os/windows_usbdk.c
libusb/os/windows_winusb.c
libusb/version_nano.h

index 4e38f0f..95a6cd7 100644 (file)
 
 #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;
index db9c919..a0bb1b4 100644 (file)
 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
index 4639a7e..9c639c1 100644 (file)
@@ -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;
 
index af28c0b..087b227 100644 (file)
@@ -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;
 }
index 4dd5337..a1662e4 100644 (file)
@@ -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 */
index 3255cf2..49f4439 100644 (file)
@@ -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;
 
index 1080026..55db699 100644 (file)
@@ -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;
 
index bb370ca..ac11496 100644 (file)
@@ -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;
 }
index 9c19ccc..ec7c025 100644 (file)
@@ -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;
 }
 
index 5454846..88eb388 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11504
+#define LIBUSB_NANO 11505