2

I have received a file descriptor for a USB device from an Android app (using getFileDescriptor()), sent it via JNI in native code and received it in a child process (AVRDude) via a Unix socket and tried to use for uploading.

So I'm getting a "Not a typewriter" error. Does it mean that file descriptor was passed incorrectly (it is a positive int and it is not equal to -1 after receiving)? Or can there be another error? Can it be a permissions issue (though permissions to UsbDevice is granted and passing via a socket seems to hold permissions, the device is not rooted)?

The code used (ser_posix.c in AVRDude 5_11_0 sources):

fprintf(stdout, "Try to set baud = %i for fd = %i", baud, usbfd);
if (!isatty(usbfd)) { // Error here!
    fprintf(stderr, "!isatty\n");
    return -ENOTTY;
}

Right after receiving from the socket file descriptor is checked to be valid (and I believe it is):

if (!(fcntl(usbfd, F_GETFL) != -1 || errno != EBADF)) {
    fprintf(stderr, "Invalid file descriptor %d, - %s", usbfd, strerror(errno));
    exit(1);
}

Originally the file descriptor in ser_posix is received like that (and I believe it's working):

fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);

In my implementation I use the file descriptor from the Android app instead. Is it what's expected?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
4ntoine
  • 19,816
  • 21
  • 96
  • 220
  • tested on 2 devices with USB-Host support of different manufacturers and Android OS versions (4.0.4 and 4.1) - the same error – 4ntoine Jun 10 '13 at 06:04
  • file descriptor is guaranteed to be not changed between getting from socket and using for setting baud rate – 4ntoine Jun 10 '13 at 06:05
  • removing "isatty" does not help since i'm getting the same error on later operations (set baud rate actually) with serial – 4ntoine Jun 11 '13 at 07:19

0 Answers0