Home > database >  How to access single USB devices of a Composite USB device?
How to access single USB devices of a Composite USB device?

Time:11-03

I would like to send data from my Windows computer to my Android Mobile.

For this, I need to activate the Accessory mode of the Android device and the USB Host mode on the Windows device.

On my Windows computer, I have a USB Composite device for the Android Mobile. This Composite USB device bundles several interfaces: Enumeration of USB Composite Devices.

Unfortunately, I can't find information how I can access the single devices of a Composite device.

I want to get a device id / path, which I can open with CreateFile to use the created HANDLE for opening a WinUsb handle with WinUsb_Initialize.

But if I try to open a Composite USB device with CreateFile, I get a ERROR_NOT_ENOUGH_MEMORY result.

I'm using this code:

_deviceHandle = CreateFile(
    deviceId, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_NONE, NULL,
    OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

... with the filename "\?\USB#VID_04E8&PID_6864#RF8NB0NMT0X#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"

It's a GUID_DEVINTERFACE_USB_DEVICE device id for a Samsung Galaxy mobile with enabled USB debugging.

As the driver Windows uses ssudbus2.sys, Version 2.17.16.0 (2021-09-14) from Samsung Electronics Co. Ltd.

The app MyPhoneExplorer can access to my mobile. So it a solution without a special driver must be possible.

How can I get this device id / path of the single USB devices inside a Composite USB device?

CodePudding user response:

The filename you are using represents the overall USB device; it doesn't represent any particular instance. A filename that represents interface will have something like &mi_01 right after the product name, where 1 is the 0-based interface number.

You might be able to just insert the appropriate &mi_xx string into your filename at the appropriate place and get it work. I think you'd also need to modify the GUID at the end of the string, which is the device interface GUID.

The more standard way to find the filename in code is to use the SetupAPI and the configuration manager (CM) API to iterate through all the child devices of your USB device. Look for a child whose device instance ID (retrieved with CM_Get_Device_ID) contains MI_xx where xx is the two-digit interface number you are looking for.

It takes a lot of effort to write up this code in standalone form, and test it, and debug it, so I will not be presenting you with a working code example. Instead, I encourage you to look at the working code in the get_interface_composite function of libusbp which does what you need to do:

https://github.com/pololu/libusbp/blob/759f48d/src/windows/interface_windows.c#L86

There are some more steps to get the path of that device node. And then the code that actually calls CreateFile and WinUsb_Initialize is here:

https://github.com/pololu/libusbp/blob/759f48d/src/windows/generic_handle_windows.c#L56-L77

  • Related