Add packed definitions for some standard USB descriptor types
authorChris Dickens <christopher.a.dickens@gmail.com>
Fri, 17 Apr 2020 18:31:55 +0000 (11:31 -0700)
committerChris Dickens <christopher.a.dickens@gmail.com>
Fri, 17 Apr 2020 18:31:55 +0000 (11:31 -0700)
These are going to be used in future commits to cleanup some code. Note
that these are prefixed as 'usbi' rather than 'usb' to avoid conflicts
with definitions provided by some system headers.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/descriptor.c
libusb/libusbi.h
libusb/os/linux_usbfs.c
libusb/version_nano.h

index 44237dd..5124494 100644 (file)
@@ -96,7 +96,7 @@ static int parse_endpoint(struct libusb_context *ctx,
        struct libusb_endpoint_descriptor *endpoint, unsigned char *buffer,
        int size, int host_endian)
 {
-       struct usb_descriptor_header header;
+       struct usbi_descriptor_header header;
        unsigned char *extra;
        unsigned char *begin;
        int parsed = 0;
@@ -214,7 +214,7 @@ static int parse_interface(libusb_context *ctx,
        int r;
        int parsed = 0;
        int interface_number = -1;
-       struct usb_descriptor_header header;
+       struct usbi_descriptor_header header;
        struct libusb_interface_descriptor *ifp;
        unsigned char *begin;
 
@@ -369,7 +369,7 @@ static int parse_configuration(struct libusb_context *ctx,
 {
        int i;
        int r;
-       struct usb_descriptor_header header;
+       struct usbi_descriptor_header header;
        struct libusb_interface *usb_interface;
 
        if (size < LIBUSB_DT_CONFIG_SIZE) {
@@ -750,7 +750,7 @@ int API_EXPORTED libusb_get_ss_endpoint_companion_descriptor(
        const struct libusb_endpoint_descriptor *endpoint,
        struct libusb_ss_endpoint_companion_descriptor **ep_comp)
 {
-       struct usb_descriptor_header header;
+       struct usbi_descriptor_header header;
        int size = endpoint->extra_length;
        const unsigned char *buffer = endpoint->extra;
 
index 2fa4e11..9622768 100644 (file)
@@ -536,11 +536,72 @@ enum usbi_transfer_timeout_flags {
         ((unsigned char *)(transfer)                   \
          - PTR_ALIGN(sizeof(struct usbi_transfer))))
 
+#ifdef _MSC_VER
+#pragma pack(push, 1)
+#endif
+
 /* All standard descriptors have these 2 fields in common */
-struct usb_descriptor_header {
-       uint8_t bLength;
-       uint8_t bDescriptorType;
-};
+struct usbi_descriptor_header {
+       uint8_t  bLength;
+       uint8_t  bDescriptorType;
+} LIBUSB_PACKED;
+
+struct usbi_device_descriptor {
+       uint8_t  bLength;
+       uint8_t  bDescriptorType;
+       uint16_t bcdUSB;
+       uint8_t  bDeviceClass;
+       uint8_t  bDeviceSubClass;
+       uint8_t  bDeviceProtocol;
+       uint8_t  bMaxPacketSize0;
+       uint16_t idVendor;
+       uint16_t idProduct;
+       uint16_t bcdDevice;
+       uint8_t  iManufacturer;
+       uint8_t  iProduct;
+       uint8_t  iSerialNumber;
+       uint8_t  bNumConfigurations;
+} LIBUSB_PACKED;
+
+struct usbi_configuration_descriptor {
+       uint8_t  bLength;
+       uint8_t  bDescriptorType;
+       uint16_t wTotalLength;
+       uint8_t  bNumInterfaces;
+       uint8_t  bConfigurationValue;
+       uint8_t  iConfiguration;
+       uint8_t  bmAttributes;
+       uint8_t  bMaxPower;
+} LIBUSB_PACKED;
+
+struct usbi_interface_descriptor {
+       uint8_t  bLength;
+       uint8_t  bDescriptorType;
+       uint8_t  bInterfaceNumber;
+       uint8_t  bAlternateSetting;
+       uint8_t  bNumEndpoints;
+       uint8_t  bInterfaceClass;
+       uint8_t  bInterfaceSubClass;
+       uint8_t  bInterfaceProtocol;
+       uint8_t  iInterface;
+} LIBUSB_PACKED;
+
+struct usbi_string_descriptor {
+       uint8_t  bLength;
+       uint8_t  bDescriptorType;
+       uint16_t wData[];
+} LIBUSB_PACKED;
+
+struct usbi_bos_descriptor {
+       uint8_t  bLength;
+       uint8_t  bDescriptorType;
+       uint16_t wTotalLength;
+       uint8_t  bNumDeviceCaps;
+} LIBUSB_PACKED;
+
+#ifdef _MSC_VER
+#pragma pack(pop)
+#endif
 
 /* shared data and functions */
 
index e1b25b0..31304d6 100644 (file)
@@ -613,7 +613,7 @@ int linux_get_device_address(struct libusb_context *ctx, int detached,
 static int seek_to_next_descriptor(struct libusb_context *ctx,
        uint8_t descriptor_type, unsigned char *buffer, int size)
 {
-       struct usb_descriptor_header header;
+       struct usbi_descriptor_header header;
        int i;
 
        for (i = 0; size >= 0; i += header.bLength, size -= header.bLength) {
index be32d4f..a2f78dc 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11501
+#define LIBUSB_NANO 11502