Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

know a usb device's endpoint

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 ?

like image 749
Vulpo Avatar asked May 07 '13 20:05

Vulpo


People also ask

How many endpoints can a USB device have?

The USB specification states a maximum of 16 endpoints for each direction. Data endpoints are bidirectional in general but can be configured to become unidirectional based on device descriptor.

What is a USB device descriptor?

The Device Descriptor (USB_DEVICE_DESCRIPTOR) is the root of the descriptor tree and contains basic device information. The unique numbers, idVendor and idProduct, identify the connected device. The Windows operating system uses these numbers to determine which device driver must be loaded.

What is interface descriptor in USB?

USB interface descriptor For activation, an application or a driver specifies the index value in the function call. Based on that information, the USB driver stack then builds a standard control request (SET INTERFACE) and sends it to the device. Note the bInterfaceClass field.


2 Answers

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.

like image 151
Vulpo Avatar answered Oct 21 '22 14:10

Vulpo


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.

like image 44
eatonphil Avatar answered Oct 21 '22 16:10

eatonphil