explanation about controltransfer in android to set up the USB communication

10,865

The first byte (bmRequestType) in the setup packet is comprised of 3 fields. The first (least significant) 5 bits are the recipient, the next 2 bits are the type, and the last bit is the direction.

If you have a value of 0x21, this has the binary representation of 100001. If you split it up into the individual fields, this is 0 01 00001, which corresponds to host-to-device, class, and interface, for the direction, type and recipient fields respectively.

So this is a control message that is being sent to a particular interface, that is defined by some standard usb class.

Since you mentioned that this was for communicating to a usb to serial adapter, I'm going to assume this is probably being sent to a communication interface, as per the USB Class Definitions for Communication Devices

Per that document, a bRequest value of 34 (0x22) corresponds to a SET_CONTROL_LINE_STATE message, while 32 (0x20) corresponds to a SET_LINE_CODING message (pages 51 and 53), which seems to make sense as part of the setup/initialization of a serial device.

The details for each of these messages is defined further down, on pages 57 and 58.

Share:
10,865
dan
Author by

dan

Updated on June 19, 2022

Comments

  • dan
    dan almost 2 years

    I am trying to write Java code to let my XOOM communicate with our embedded device via USB to Serial cable.

    I used this chunck of code:

    connection.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
    connection.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80,
                                    0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);
    

    I know this is to send the setup request to the USB device. I do not understand why the requestType is 0x21, why requestID is 32, 34, etc.

    According to the specs here: http://www.beyondlogic.org/usbnutshell/usb6.shtml#SetupPacket, in the standard device request, standard interface request and standard endpoint request, none of the requestType is 0x21 and none of the requestID is 32 or 34. Is there any explaination for these parameters including the transmitted datebuffer??