Android Usb Host: How to send control transfer with URB Function set to URB_FUNCTION_CLASS_ENDPOINT?

0

I'm trying to reverse engineer USB comunication betweeny a device and PC with an Android device as USB host(USB OTG). I'm using Usb Host classes provided by Android SDK (https://developer.android.com/guide/topics/connectivity/usb/host)

I have recorded communication between the device and PC using wireshark as following:

USB URB
[Source: host]
[Destination: 1.3.0]
USBPcap pseudoheader length: 28
IRP ID: 0xffffa6827a5a4010
IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000)
URB Function: URB_FUNCTION_CLASS_INTERFACE (0x001b)
IRP information: 0x00, Direction: FDO -> PDO
URB bus id: 1
Device address: 3
Endpoint: 0x00, Direction: OUT
URB transfer type: URB_CONTROL (0x02)
Packet Data Length: 8
Control transfer stage: Setup (0)
[bInterfaceClass: Unknown (0xffff)]

URB setup
bmRequestType: 0x21
bRequest: 1
wValue: 0x0102
wIndex: 1280 (0x0500)
wLength: 2

I am able to send the same message with the following code and it works fine:

fun connectDevice(context: Context, device: UsbDevice) {
        val usbManager = context.getSystemService(Context.USB_SERVICE) as UsbManager
        usbInterface = device.getInterface(0).also { intf ->
            connection = usbManager.openDevice(device)
            try{
                val claimed = connection?.claimInterface(intf,true) ?: false
                if (connection != null && claimed) {
                    LogUtil.d("USB CONNECTED")
                } else {
                    LogUtil.d("USB NOT CONNECTED")
                    connection?.close()
                    connection = null
                }

            }catch (e: Exception){
                LogUtil.d("USB EXCEPTION ${e.message}")
                e.printStackTrace()
            }
        }
    }
        
private fun setVolume(input: Int, output: Int, value: ByteArray): String {
        return connection?.controlTransfer(
            0x21,//request type
            1,//
            output.shl(8).or(input),//output//input 0xffff, 0x (01-09) (01-09,0a-0f,10)
            0x0500,//wIndex
            value,//
            2,//length
            USB_TIMEOUT// timeout
        ).toString()
    }

Now I'm trying to send a second type of control transfer message the same way:

USB URB

[Source: host]
[Destination: 1.2.0]
USBPcap pseudoheader length: 28
IRP ID: 0xffffa6827b3f0010
IRP USBD_STATUS: USBD_STATUS_SUCCESS (0x00000000)
URB Function: URB_FUNCTION_CLASS_ENDPOINT (0x001c)
IRP information: 0x00, Direction: FDO -> PDO
URB bus id: 1
Device address: 2
Endpoint: 0x00, Direction: OUT
URB transfer type: URB_CONTROL (0x02)
Packet Data Length: 8
Control transfer stage: Setup (0)
[bInterfaceClass: Unknown (0xffff)]

URB setup
bmRequestType: 0x22
bRequest: 1
wValue: 0x0100
wIndex: 1 (0x0001)
wLength: 3

with the following method:

fun setInternalSampleRate(value: ByteArray): String{
        return connection?.controlTransfer(
            0x22,//request type
            1,//
            0x0100,
            1,//wIndex
            value,//
            3,//length
            USB_TIMEOUT// timeout
        ).toString()
    }

However it returns an error. The only difference between the two calls I can see in wireshark (accept for URB setup which I have change accordingly) is value of the URB Function parameter:

URB_FUNCTION_CLASS_INTERFACE (0x001b) vs. URB_FUNCTION_CLASS_ENDPOINT (0x001c)

is there a way to send a USB control transfer with URB_FUNCTION_CLASS_ENDPOINT parameter with Android SDK?

android
usb
usb-otg
usbmanager

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0