Interface can not be changed on an already open device
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 7 Oct 2011 13:59:54 +0000 (15:59 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 7 Oct 2011 13:59:54 +0000 (15:59 +0200)
Based upon code from Uwe Bonnes, improved by me.

src/ftdi.c

index 1f45e95..59a9eea 100644 (file)
@@ -149,12 +149,23 @@ struct ftdi_context *ftdi_new(void)
     \retval  0: all fine
     \retval -1: unknown interface
     \retval -2: USB device unavailable
+    \retval -3: Device already open, interface can't be set in that state
 */
 int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface)
 {
     if (ftdi == NULL)
         ftdi_error_return(-2, "USB device unavailable");
 
+    if (ftdi->usb_dev != NULL)
+    {
+        int check_interface = interface;
+        if (check_interface == INTERFACE_ANY)
+            check_interface = INTERFACE_A;
+
+        if (ftdi->index != check_interface)
+            ftdi_error_return(-3, "Interface can not be changed on an already open device");
+    }
+
     switch (interface)
     {
         case INTERFACE_ANY: