Search code examples
endpointlibusb

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 ?


Solution

  • 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.