From 1c5fa36b67bc30742eee94ed3e3648fcd4640f24 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Fri, 7 Oct 2011 15:59:54 +0200 Subject: [PATCH] Interface can not be changed on an already open device Based upon code from Uwe Bonnes, improved by me. --- src/ftdi.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/src/ftdi.c b/src/ftdi.c index 1f45e95..59a9eea 100644 --- a/src/ftdi.c +++ b/src/ftdi.c @@ -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: -- 1.7.1