13

Is there a bash command, a program or a libusb function (although I did not find one) which indicates me what are the OUT or IN endpoints of a usb device ?

For example, bNumEndpoints of libusb_interface_descriptor (from libusb1.0 library) shows me my usb drive has 3 endpoints, but how can I know what is their idnumber ?

Vulpo
  • 873
  • 1
  • 9
  • 25

2 Answers2

14

After you have claimed the device, run this (where $ represents the terminal entry point):

$ sudo lsusb -v -d 16c0:05df

Where 16c0:05df are your vendor and product ids separated by a colon. (If you don't know these, type lsusb and figure out which device is yours by unplugging and re-running lsusb)

If you get confused use the lsusb man page:

http://linux.die.net/man/8/lsusb

Then once your description comes up, find the line labeled bEndpointAddress and the hex code following will be the endpoint for that specific Report.

eatonphil
  • 13,115
  • 27
  • 76
  • 133
10

I finally found the answer in lubusb-1.0. In was actually not a function, but a struct field :

uint8_t libusb_endpoint_descriptor::bEndpointAddress

The address of the endpoint described by this descriptor.

Bits 0:3 are the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, see libusb_endpoint_direction.

For each interface for the usb drive, I just had to write these lines to display the available endpoints :

cout<<"Number of endpoints: "<<(int)interdesc->bNumEndpoints<<endl;
for(int k=0; k<(int)interdesc->bNumEndpoints; k++) {
        epdesc = &interdesc->endpoint[k];
        cout<<"Descriptor Type: "<<(int)epdesc->bDescriptorType<<endl;
    cout<<"EP Address: "<<(int)epdesc->bEndpointAddress<<endl;
}

Where epdesc is the libusb_endpoint_descriptor and interdesc is the libusb_interface_descriptor.

Vulpo
  • 873
  • 1
  • 9
  • 25
  • 4
    Great code snippet/example, thank you! I hate the auto-generated docs like the one libusb has, it goes through every field of every structure, but no indication or example of how to obtain the structure in the first place. – Violet Giraffe May 19 '21 at 13:21