You are not logged in.

#1 2014-10-05 00:08:47

darArch
Member
From: Scotland
Registered: 2013-07-25
Posts: 10

USB Driver Development

Hello

I am currently developing a USB driver for the Xbox 360 Controller for a project at university. I know that other solutions already exist (xpad, xboxdrv) however my project supervisor thought that this would provide a good entry to the world of systems programming. I currently have a driver which loads into and out of the kernel successfully, however I have yet to complete the probe and disconnect functions so it doesn't do anything when it's in there.

My questions are as follows:

Firstly, does anybody know of any good books or online resources providing tutorials for this kind of programming? I already have a reasonable selection at my disposal, including Linux Device Drivers, but I figure it can't hurt to have as wide a selection of potential resources as possible.

Secondly, and less broadly, I ran

sudo lsusb -v -s 4:4

and got the following output:

Bus 004 Device 004: ID 045e:028e Microsoft Corp. Xbox360 Controller
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass       255 Vendor Specific Subclass
  bDeviceProtocol       255 Vendor Specific Protocol
  bMaxPacketSize0         8
  idVendor           0x045e Microsoft Corp.
  idProduct          0x028e Xbox360 Controller
  bcdDevice            1.14
  iManufacturer           1 ©Microsoft Corporation
  iProduct                2 Controller
  iSerial                 3 0CF14C5
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          153
    bNumInterfaces          4
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     93 
      bInterfaceProtocol      1 
      iInterface              0 
      ** UNRECOGNIZED:  11 21 00 01 01 25 81 14 00 00 00 00 13 01 08 00 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               8
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           4
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     93 
      bInterfaceProtocol      3 
      iInterface              0 
      ** UNRECOGNIZED:  1b 21 00 01 01 01 82 40 01 02 20 16 83 00 00 00 00 00 00 16 03 00 00 00 00 00 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               2
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval              64
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval              16
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     93 
      bInterfaceProtocol      2 
      iInterface              0 
      ** UNRECOGNIZED:  09 21 00 01 01 22 84 07 00
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval              16
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    253 
      bInterfaceProtocol     19 
      iInterface              4 Xbox Security Method 3, Version 1.00, © 2005 Microsoft Corporation. All rights reserved.
      ** UNRECOGNIZED:  06 41 00 01 01 03
Device Status:     0x0002
  (Bus Powered)
  Remote Wakeup Enabled

Can anyone advise on what the lines with UNRECOGNIZED indicate? I have Googled and found results (mainly from various mailing lists) where people have posted output containing similar lines to those in mine above, however I haven't seen any where the meaning of those lines is divulged.

Thanks in advance to anybody who can help.

Offline

#2 2014-10-05 01:14:18

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,345

Re: USB Driver Development

http://lwn.net/Kernel/LDD3/ is the best I have seen.  You have seen that already hmm


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2014-10-06 12:42:33

darArch
Member
From: Scotland
Registered: 2013-07-25
Posts: 10

Re: USB Driver Development

Thanks for the response.

Any thoughts on what those UNRECOGNIZED lines may be?

Offline

#4 2014-11-01 08:02:47

wtx
Member
Registered: 2014-06-09
Posts: 82

Re: USB Driver Development

Unfortunately I have never seen any books about writing USB drivers for Linux kernel - books that describe in details all the process of programming of USB drivers.
You have to be familiar with USB stack from Linux kernel to write USB drivers. I have written a few USB drivers for Linux kernel and I also had to learn how USB stack in Linux kernel works.
To answer what UNRECOGNIZED lines may be I also suggest to analyse sources of lsusb and linux USB stack kernel.
By the way are you writing USB device driver or USB host side driver? You didn't write about it...


Edit: Maybe those UNRECOGNIZED data means extra data that usb-host didn't expected?

Last edited by wtx (2014-11-01 12:25:39)

Offline

#5 2014-11-02 12:27:20

mauritiusdadd
Member
From: Benevento, Italy
Registered: 2013-10-27
Posts: 776

Re: USB Driver Development

Hi darArch,

darArch wrote:

      ** UNRECOGNIZED:  11 21 00 01 01 25 81 14 00 00 00 00 13 01 08 00 00
      ...
      ** UNRECOGNIZED:  1b 21 00 01 01 01 82 40 01 02 20 16 83 00 00 00 00 00 00 16 03 00 00 00 00 00 00
      ...
      ** UNRECOGNIZED:  09 21 00 01 01 22 84 07 00
      ...
      ** UNRECOGNIZED:  06 41 00 01 01 03
      ...

each line with UNRECOGNIZED represents a USB descriptor. The UNRECOGNIZED word indicates that libusb was not able to recognize the descriptor obtained from your device and thus lsusb shows the descriptor data as a sequence of bytes. All the USB descriptors have the following structure (for more information look here):

  • The first byte represents the total lenght in bytes of the descriptor (including this byte)

  • The second byte represents the type of the descriptor

Unfortunately, I was unable to identify the descriptor type for the last line, but in the others the value of 0x21 (LIBUSB_DT_HID) for second byte indicates they are HID (Human Interface Device) descriptors, however libusb itself can't handle them without a compatible driver:

http://www.libusb.org/wiki/APIs wrote:

libusb is not suited for HID class devices. While it is possible to use libusb with HID class devices it requires the original HID class driver to be replaced by a driver which supports libusb, and this leads to a quite poor user experience on any platform other than Linux.

In order to know what the remaining bytes mean, you should check the HID specifications. In aforementioned specifications, in the section 5.1, there is a scheme that shows a basic  structure of a HID descriptor. Comparing this scheme with your lsusb output we have the confirmation that each of the first three UNRECOGNIZED lines corresponds to a HID Descriptor:

# your lsusb structure               # HID descriptor structure
Device Descriptor                    Device Descriptor
|                                    |
+-Configuration Descriptor           +-Configuration Descriptor
  |                                    |
  +-Interface Descriptor               +-Interface Descriptor
  | |                                  | |
  | +-UNRECOGNIZED                     | +-HID Descriptor
  | |                                  | | |
  | |                                  | | +-Report Descriptor
  | |                                  | | |
  | |                                  | | +-Physical Descriptor
  | +-Endpoint Descriptor              | +-Endpoint Descriptor
  |                                    |   
  ...                                  ...

Looking at section 6.2.1 instead, where there is a detailed description of a HID descriptor, we can decode for example the last of them

NUM 00 01 02 03 04 05 06 07 08
VAL 09 21 00 01 01 22 84 07 00

HID Descriptor:
    bLength                 9
    bDescriptorType         21
    bcdHID                  1.0    // 0100 means 1.0
    bCountryCode            01
    bNumDescriptors         22
    bRDescriptorType        84
    wDescriptorLength       0007

PS: forgive me for the long post tongue


About me - github

-- When you have eliminated the impossible, whatever remains, however improbable, must be the truth -- Spock | Sherlock Holmes

Offline

Board footer

Powered by FluxBB