libftdi: (tomj) added ftdi_usb_get_strings function from external patch
authorThomas Jarosch <opensource@intra2net.com>
Mon, 11 Dec 2006 15:30:18 +0000 (15:30 +0000)
committerThomas Jarosch <opensource@intra2net.com>
Mon, 11 Dec 2006 15:30:18 +0000 (15:30 +0000)
ChangeLog
src/ftdi.c
src/ftdi.h

index b84a8d5..d137876 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 New in 0.8
 ----------
 * Complete doxygen documentation and examples
+* ftdi_usb_get_strings function to get device ID strings (Matthijs ten Berge)
 * Fix ftdi_read_pins on PowerPC systems (Thomas Fischl)
 * Automatically detach ftdi_sio kernel driver (Uwe Bonnes and Intra2net)
 * Configurable flow control (Lorenz Moesenlechner and Matthias Kranz)
index 8399030..b7876fa 100644 (file)
@@ -196,6 +196,65 @@ void ftdi_list_free(struct ftdi_device_list **devlist)
 }
 
 /**
+    Return device ID strings from the usb device.
+
+    The parameters manufacturer, description and serial may be NULL
+    or pointer to buffers to store the fetched strings.
+
+    \param ftdi pointer to ftdi_context
+    \param dev libusb usb_dev to use
+    \param manufacturer Store manufacturer string here if not NULL
+    \param mnf_len Buffer size of manufacturer string
+    \param description Store product description string here if not NULL
+    \param desc_len Buffer size of product description string
+    \param serial Store serial string here if not NULL
+    \param serial_len Buffer size of serial string
+
+    \retval   0: all fine
+    \retval  -1: wrong arguments
+    \retval  -4: unable to open device
+    \retval  -7: get product manufacturer failed
+    \retval  -8: get product description failed
+    \retval  -9: get serial number failed
+    \retval -10: unable to close device
+*/
+int ftdi_usb_get_strings(struct ftdi_context * ftdi, struct usb_device * dev,
+        char * manufacturer, int mnf_len, char * description, int desc_len, char * serial, int serial_len)
+{
+    if ((ftdi==NULL) || (dev==NULL))
+        return -1;
+
+    if (!(ftdi->usb_dev = usb_open(dev)))
+        ftdi_error_return(-4, usb_strerror());
+
+    if (manufacturer != NULL) {
+        if (usb_get_string_simple(ftdi->usb_dev, dev->descriptor.iManufacturer, manufacturer, mnf_len) <= 0) {
+            usb_close (ftdi->usb_dev);
+            ftdi_error_return(-7, usb_strerror());
+        }
+    }
+
+    if (description != NULL) {
+        if (usb_get_string_simple(ftdi->usb_dev, dev->descriptor.iProduct, description, desc_len) <= 0) {
+            usb_close (ftdi->usb_dev);
+            ftdi_error_return(-8, usb_strerror());
+        }
+    }
+
+    if (serial != NULL) {
+        if (usb_get_string_simple(ftdi->usb_dev, dev->descriptor.iSerialNumber, serial, serial_len) <= 0) {
+            usb_close (ftdi->usb_dev);
+            ftdi_error_return(-9, usb_strerror());
+        }
+    }
+
+    if (usb_close (ftdi->usb_dev) != 0)
+        ftdi_error_return(-10, usb_strerror());
+
+    return 0;
+}
+
+/**
     Opens a ftdi device given by a usb_device.
 
     \param ftdi pointer to ftdi_context
index 2d3a5cc..126c85a 100644 (file)
@@ -223,6 +223,10 @@ extern "C" {
     int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
                           int vendor, int product);
     void ftdi_list_free(struct ftdi_device_list **devlist);
+    int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct usb_device *dev,
+                             char * manufacturer, int mnf_len,
+                             char * description, int desc_len,
+                             char * serial, int serial_len);
 
     int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
     int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,