ioctl returns -1 in android USB bulk transfer

2.2k views Asked by At

I have an android app which creates a connection to a USB device and have to receive data through a particular endpoint. I am handling the data transfer part in native code. The app is able to find the device, open connection and find the required endpoint. The data reading part is in the native code, where an ioctl call is made inside a while loop.

int bytesTransferred = ioctl(g_fileDescriptor, USBDEVFS_BULK, &ctrl);

This g_fileDescriptor is the descriptor for the USB connection.

Second parameter is to indicate that it is bulk transfer.

The third parameter has the structure usbdevfs_bulktransfer (which has the endpoint address, bufferlength - 16KB, data placeholder, timeout-1000msec)

I tried this using two USB devices. First device works good. Data is being read successfully.

Second device seems to give some problem. My app finds the device, connects to it, finds the required endpoint. But the ioctl call always returns -1. And I noted that the time interval between two successive ioctl calls is 0.99 sec on an average (which is approximately equal to the timeout value I set).

So I have three questions here.

  1. Can I conclude that timeout is the reason for ioctl returning -1 ?

  2. Can strerror(errorno) find what is exactly the problem ? (Because I read that ioctl returns -1 on error and sets the corresponding errorcode in system's 'errno' variable)

  3. What are the situations in which Timeout occurs in case of bulk transfer ?

1

There are 1 answers

0
Sean On

1.Can I conclude that timeout is the reason for ioctl returning -1 ? => If you set ctrl.timeout to "0"(zero), you can wait for an infinite time. By this, you can prove your conclusion.