Re: lsusb USB descriptor fields byteswapped on BE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 27 October 2009 23:38:29 Greg KH wrote:
> On Tue, Oct 27, 2009 at 11:28:16PM +0100, Michael Buesch wrote:
> > On Tuesday 27 October 2009 22:20:05 Greg KH wrote:
> > > On Tue, Oct 27, 2009 at 10:00:21PM +0100, Michael Buesch wrote:
> > > > Hi Greg,
> > > > 
> > > > The following fields are byteswapped in lsusb on BigEndian machines:
> > > > 
> > > > wTotalLength		(Config descriptor)
> > > > wMaxPacketSize		(EP descriptor)
> > > 
> > > How so?  Can you provide the output of 'lsusb -v' so I can see it?
> > 
> > 
> > Here's an example prototype device for which I know what the values must look like.
> > Other devices look similiar.
> > 
> > wTotalLength 12288 is 0x30 swapped.
> > wMaxPacketSize 0x4000 is 0x40 swapped.
> > 0x30 and 0x40 would be the correct values. So it certainly is a byteorder issue.
> > 
> > This is lsusb version 0.73 (Debian Lenny stable). I didn't try a newer upstream version.
> 
> This was fixed back in May of 2006 and should have showed up in the 0.73
> release.  If you could, can you grab a newer version of usbutils, like
> the upstream version, to see if it is still an issue or not?

version 0.86 shows the same behavior.
The endianness check in lsusb.c does also work correctly.

The following patch will produce the correct result.

However, the patch obviously is incorrect.
I suspect that libusb (or the kernel) already swapped the values for us.
Look at those other 16bit values like idProduct, idVendor, bcdXXX...
Those are correctly displayed and usbutils does _not_ byteswap them.
So I guess either libusb (or the kernel) does.


--- usbutils-0.86.orig/lsusb.c
+++ usbutils-0.86/lsusb.c
@@ -41,7 +41,7 @@
 
 #include <getopt.h>
 
-#if (__BYTE_ORDER == __LITTLE_ENDIAN)
+#if (__BYTE_ORDER == __LITTLE_ENDIAN) ||1
   #define le16_to_cpu(x) (x)
 #elif (__BYTE_ORDER == __BIG_ENDIAN)
   #define le16_to_cpu(x) bswap_16(x)






Broken output from unpatched 0.86:

Bus 003 Device 036: ID 6666:1337  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        16
  idVendor           0x6666 
  idProduct          0x1337 
  bcdDevice            0.01
  iManufacturer           1 Michael Buesch
  iProduct                2 PDIUSB test device
  iSerial                 3 1
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength        12288
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          4 Configuration 1
    bmAttributes         0xc0
      Self Powered
    MaxPower               50mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass         3 
      bInterfaceSubClass      1 
      bInterfaceProtocol      2 
      iInterface              5 Interface 1
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Unknown
          bNumDescriptors         1
          bDescriptorType        34 (null)
          wDescriptorLength      65
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)

-- 
Greetings, Michael.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux