#Claim interface of composite device using usb4java

1 messages · Page 1 of 1 (latest)

cunning musk
#

Hello, I am trying to get open communication with libusb device. The device has HID and Bulk. When I try to open device LibUsb.open(usbDevice, handle);, LibUsb log shows:

[ 0.067814] [00004b04] libusb: debug [libusb_open] open 1.21
[ 0.067975] [00004b04] libusb: debug [hid_open] set maximum input buffer size to 512
[ 0.067995] [00004b04] libusb: debug [hid_open] 5 HID input report value(s) found
[ 0.067999] [00004b04] libusb: debug [hid_open]   Report ID: 0x01
[ 0.068002] [00004b04] libusb: debug [hid_open]   Report ID: 0x02
[ 0.068004] [00004b04] libusb: debug [hid_open]   Report ID: 0x03
[ 0.068006] [00004b04] libusb: debug [hid_open]   Report ID: 0x04
[ 0.068008] [00004b04] libusb: debug [hid_open]   Report ID: 0x06
[ 0.068010] [00004b04] libusb: debug [hid_open] 5 HID output report value(s) found
[ 0.068012] [00004b04] libusb: debug [hid_open]   Report ID: 0x01
[ 0.068014] [00004b04] libusb: debug [hid_open]   Report ID: 0x03
[ 0.068016] [00004b04] libusb: debug [hid_open]   Report ID: 0x04
[ 0.068018] [00004b04] libusb: debug [hid_open]   Report ID: 0x05
[ 0.068020] [00004b04] libusb: debug [hid_open]   Report ID: 0x06
[ 0.068022] [00004b04] libusb: debug [hid_open] 0 HID feature report value(s) found

But that's HID and I want to communicate using bulk. Can't seem to figure it out.

tidal trellisBOT
#

<@&987246964494204979> please have a look, thanks.

tidal trellisBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

cunning musk
#

Logs that it sees HID and bulk:

[ 0.048676] [0000234c] libusb: debug [winusb_get_device_list] setting composite interface for [77]:
[ 0.048679] [0000234c] libusb: debug [set_composite_interface] interface[1] = \\.\HID#VID_273E&PID_0017&MI_01#9&35F8809E&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.049252] [0000234c] libusb: debug [get_api_type] driver(s): libusb0
[ 0.049283] [0000234c] libusb: debug [get_api_type] matched driver name against libusb0
[ 0.049290] [0000234c] libusb: debug [winusb_get_device_list] setting composite interface for [77]:
[ 0.049293] [0000234c] libusb: debug [set_composite_interface] interface[0] = \\.\USB#VID_273E&PID_0017&MI_00#8&1535F924&0&0000#{CD122D94-35A2-4BD6-A49D-08424651BE07}
thorny flint
#

Can we please see some code?

cunning musk
#
    private void findDevices_LowLevel(boolean log) throws LibUsbException {
        DeviceList list = new DeviceList();
        int result = LibUsb.getDeviceList(null, list);
        if (result < 0) throw new LibUsbException("Unable to get device list", result);

        try {
            for (Device usbDevice : list) {
                DeviceDescriptor descriptor = new DeviceDescriptor();
                result = LibUsb.getDeviceDescriptor(usbDevice, descriptor);
                if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);

                int vid = descriptor.idVendor();
                int pid = descriptor.idProduct();
                boolean isFod = (vid == VENDOR_ID && pid == PRODUCT_ID);
                boolean isHub = descriptor.bDeviceClass() == 9;

                if (isFod) {
                    fodCnt++;

                    DeviceHandle handle = new DeviceHandle();
                    result = LibUsb.open(usbDevice, handle);
                    if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to open USB device", result);

                    result = LibUsb.claimInterface(handle, INTERFACE_ID);
                    if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to claim interface", result);

                }
            }
        } finally {
            LibUsb.freeDeviceList(list, true);
        }
    }
#

This is the function I am calling. I loop trough all devices. Find device by VID PID and try to claim interface.

#

But I get exception that it is not able to claim interface

#

And that is not surprising because it opens the HID device for some reason

thorny flint
#

Does your user group have permission to access this device? And if so, do you have permissions to read/write to this device?

cunning musk
#

Yep

#

I have some random software that is somehow able to read/write to bulk

thorny flint
#

Where are you writing from? Can we see that part of the code? I just see you trying to access the device but not doing any IO operations.

cunning musk
#

The problem is that I would love to do IO operations, but I can't because I am not able to claim interface. If I would be able to claim interface I could do any IO operation I want.

#

I removed IO code because in this case it is not relevant, because I can't open communication to device

thorny flint
#

Okay sorry for the misunderstanding, I thought that you were having problems writing to the device but in fact you're having problems connecting to the device.

#

Are you running the code under the same user group that has access to the device?

#

Doesn't hurt to triple check

#

It might also be of use to say what kind of device it is. Is it a drive? It could have a physical hardware lock on it.

thorny flint
#

Also try and debug it

Is ```java
if(isFod) {

}``` ever evaluating to true?

thorny flint
#

Do you have the driver installed?

cunning musk
cunning musk
thorny flint
#

Okay, all seems good. I'm just trying to rubber duck with ya. I don't have any experience with the lib, personally.

#

I'll do a little bit more Googling, one sec.

#

What other return values can LibUsb#open return other than success?

#

It might not be failing per se, but it might be giving you something else.

cunning musk
thorny flint
#

Print out the value, it may not be a success, but it might not be a fail.

#

It could be no mem, etc

cunning musk
thorny flint
#

Again, I'm not familiar with the lib, but your brain + a half is better than none 😛

#

Okay so it is succeding

cunning musk
#

Yeah 🙂

thorny flint
#

And it's not throwing any exceptions

cunning musk
#

Yes

thorny flint
#

So to me, it looks like your code is working as intended. Could you try writing to it?

#

It's passing every check

cunning musk
#

It throwing when I try to open interface

thorny flint
#

On this line?

result = LibUsb.claimInterface(handle, INTERFACE_ID);
cunning musk
#

Yes

#

Ok so basically it opens HID communication. That can be seen in logs:

[ 0.052862] [00005c54] libusb: debug [libusb_open] open 1.22
[ 0.053022] [00005c54] libusb: debug [hid_open] set maximum input buffer size to 512
[ 0.053039] [00005c54] libusb: debug [hid_open] 5 HID input report value(s) found
[ 0.053043] [00005c54] libusb: debug [hid_open]   Report ID: 0x01
[ 0.053045] [00005c54] libusb: debug [hid_open]   Report ID: 0x02
[ 0.053047] [00005c54] libusb: debug [hid_open]   Report ID: 0x03
[ 0.053049] [00005c54] libusb: debug [hid_open]   Report ID: 0x04
[ 0.053051] [00005c54] libusb: debug [hid_open]   Report ID: 0x06
[ 0.053053] [00005c54] libusb: debug [hid_open] 5 HID output report value(s) found
[ 0.053056] [00005c54] libusb: debug [hid_open]   Report ID: 0x01
[ 0.053058] [00005c54] libusb: debug [hid_open]   Report ID: 0x03
[ 0.053060] [00005c54] libusb: debug [hid_open]   Report ID: 0x04
[ 0.053062] [00005c54] libusb: debug [hid_open]   Report ID: 0x05
[ 0.053064] [00005c54] libusb: debug [hid_open]   Report ID: 0x06
[ 0.053068] [00005c54] libusb: debug [hid_open] 0 HID feature report value(s) found

It reads hid_open

#

That's why it throws error afterwards

#

I want to open not hid but bulk

thorny flint
#

iirc you open it as per normal, and then attempt to write as bulk

#

You don't open as bulk

#

you let the device tell you what you can and can't do

cunning musk
#

I want to open as bulk, not hid

thorny flint
#

Looking at their docs, you open it and then attempt a bulk transfer

cunning musk
#

In this part of log it can be seen that same device is set to composite because it can be both HID and bulk

[ 0.049159] [00001a6c] libusb: debug [winusb_get_device_list] setting composite interface for [77]:
[ 0.049164] [00001a6c] libusb: debug [set_composite_interface] interface[1] = \\.\HID#VID_273E&PID_0017&MI_01#9&35F8809E&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.049740] [00001a6c] libusb: debug [get_api_type] driver(s): libusb0
[ 0.049769] [00001a6c] libusb: debug [get_api_type] matched driver name against libusb0
[ 0.049775] [00001a6c] libusb: debug [winusb_get_device_list] setting composite interface for [77]:
[ 0.049778] [00001a6c] libusb: debug [set_composite_interface] interface[0] = \\.\USB#VID_273E&PID_0017&MI_00#8&1535F924&0&0000#{CD122D94-35A2-4BD6-A49D-08424651BE07}
thorny flint
cunning musk
thorny flint
#

You just connect to the device using the handle, which in turn uses the vendor id and product id

#

That gives you the handle

#

Then you claim the interface with the handle

cunning musk
#

As it states, if you want to communicate you have to claim interface

thorny flint
#

There's no mention of what kind of connection it is

#

Yes I understand that

#

But you don't tell it how to connect, just what to connect to.

#

Then you attempt to do the transfer

cunning musk
thorny flint
#

But you don't tell it how to connect, just what device to connect to.

#

With the vendor and product id

#

Mmmm I see

cunning musk
#

Yeah I understand that, but currently I can't find a way to tell it not to open hid, but open bulk

thorny flint
#

You don't

#

That's determined when you try and transfer to it

#

You connect to the device, agnostic to the way of which you're trying to send data to it.

#

But you're not able to connect to it at all

cunning musk
#

But I can't claim interface tho

thorny flint
#

Exactly

#

So I think it may not be your code that's the problem

#

You may have the wrong handle

#

And or you don't have permissions

#

Which you said you do

#

So what I would do next is make sure your handle and descriptor are both valid

cunning musk
#

I have other device that is only bulk and it connects and claims interface perfectly

thorny flint
#

Does the descriptor have information such as the name of the device you're trying to access?

#

Print the vendor or something

cunning musk
#
[ 0.050586] [0000388c] libusb: debug [libusb_open] open 1.23
[ 0.050619] [0000388c] libusb: debug [libusb_claim_interface] interface 0
[ 0.050664] [0000388c] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.050673] [0000388c] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 82 to interface 0
[ 0.050677] [0000388c] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 02 to interface 0

This is a log of successful connection to other device that is bulk only

thorny flint
#

Print the name of the device that you're attempting to connect to

#

I'll also tag a friend who has a lot of experience with this sort of thing

#

@radiant geode

cunning musk
#

If I try to get config descriptor I get error:

[ 0.059698] [000048d4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.059716] [000048d4] libusb: error [parse_endpoint] invalid extra ep desc len (0)
[ 0.059720] [000048d4] libusb: error [raw_desc_to_config] parse_configuration failed with error -1
radiant geode
cunning musk
#

Found out that on mac this code works somehow

thorny flint
#

So then as I suspected it probably is some permission thing

#

That or could be your physical port

cunning musk
#

Tried on 2 windows machines and 2 macs

#

Works only on macs

#

As I can see its problem of library itself

#

Libusb

thorny flint
#

Oof

#

Submit an issue and use a different library 😂

solar sorrel
#

Submit an issue and use a different library spoderman
Submit an issue and fix it gigachad