Search code examples
androidchidlibusb

AOA 2.0 HID Device Unsupported Control Request On Sending HID Event


I am trying to use the AOA 2.0 protocol and libusb to send key presses to an Android device. I am able to put the device accessory mode and and able to register the HID device. However whenever I send an event I get the error:

libusb: debug [handle_control_completion] unsupported control request

I think my problem may be the hid descriptor that I am sending, however I found one online that should work.

Here is my relevant code with the descriptor:

char DESC[] = {

            0x05, 0x01, /* Usage Page (Generic Desktop)      */
            0x09, 0x06, /* Usage (Keyboard)                  */
            0xA1, 0x01, /* Collection (Application)          */
            0x05, 0x07, /* Usage Page (Keyboard)             */
            0x19, 224,  /* Usage Minimum (224)               */
            0x29, 231,  /* Usage Maximum (231)               */
            0x15, 0x00, /* Logical Minimum (0)               */
            0x25, 0x01, /* Logical Maximum (1)               */
            0x75, 0x01, /* Report Size (1)                   */
            0x95, 0x08, /* Report Count (8)                  */
            0x81, 0x02, /* Input (Data, Variable, Absolute)  */
            0x81, 0x01, /* Input (Constant)                  */
            0x19, 0x00, /* Usage Minimum (0)                 */
            0x29, 101,  /* Usage Maximum (101)               */
            0x15, 0x00, /* Logical Minimum (0)               */
            0x25, 101,  /* Logical Maximum (101)             */
            0x75, 0x08, /* Report Size (8)                   */
            0x95, 0x06, /* Report Count (6)                  */
            0x81, 0x00, /* Input (Data, Array)               */
            0x05, 0x08, /* Usage Page (LED)                  */
            0x19, 0x01, /* Usage Minimum (1)                 */
            0x29, 0x05, /* Usage Maximum (5)                 */
            0x15, 0x00, /* Logical Minimum (0)               */
            0x25, 0x01, /* Logical Maximum (1)               */
            0x75, 0x01, /* Report Size (1)                   */
            0x95, 0x05, /* Report Count (5)                  */
            0x91, 0x02, /* Output (Data, Variable, Absolute) */
            0x95, 0x03, /* Report Count (3)                  */
            0x91, 0x01, /* Output (Constant)                 */
            0xC0    /* End Collection                    */
};
int response;
//Register the HID device
response = libusb_control_transfer(handle, 0x40, 54, 1, sizeof(DESC), NULL, 0, 0);
if (response < 0) {error(response); return -1;}
// Send the device descriptor
response = libusb_control_transfer(handle, 0x40, 56, 1, 0, DESC, sizeof(DESC), 0);
if (response < 0) {error(response); return -1;}
usleep(1000);
// OK so here is the problem, this request should just send the next song ket 
// However I am getting unsupported control request.
char report[] = {0x07,0x00,0xEC,0x00,0x00,0x00,0x00,0x00};
response = libusb_control_transfer(handle, 0x40, 57, 1, 0, report, sizeof(report), 0);
if (response < 0) {error(response); return -1;} 
return 0;

EDIT: Ok so I did some more digging around in the android adk code and I found a generic keyboard descriptor with some sample code. Now it seems to not fail like one out of every 10ish attempts which is very weird? I updated the code as well.


Solution

  • My problem was that I did not sleep long enough after sending the device descriptor.

    usleep(100000);
    

    Fixed it