ftdi.c - description
-------------------
begin : Fri Apr 4 2003
- copyright : (C) 2003-2010 by Intra2net AG
+ copyright : (C) 2003-2011 by Intra2net AG and the libftdi developers
email : opensource@intra2net.com
***************************************************************************/
char string[256];
int i = 0;
- if (libusb_init(&ftdi->usb_ctx) < 0)
- ftdi_error_return(-11, "libusb_init() failed");
-
if (ftdi == NULL)
ftdi_error_return(-11, "ftdi context invalid");
+ if (libusb_init(&ftdi->usb_ctx) < 0)
+ ftdi_error_return(-11, "libusb_init() failed");
+
if (libusb_get_device_list(ftdi->usb_ctx, &devs) < 0)
ftdi_error_return(-12, "libusb_get_device_list() failed");
{
if (libusb_get_string_descriptor_ascii(ftdi->usb_dev, desc.iProduct, (unsigned char *)string, sizeof(string)) < 0)
{
- libusb_close (ftdi->usb_dev);
+ ftdi_usb_close_internal (ftdi);
ftdi_error_return_free_device_list(-8, "unable to fetch product description", devs);
}
if (strncmp(string, description, sizeof(string)) != 0)
{
- libusb_close (ftdi->usb_dev);
+ ftdi_usb_close_internal (ftdi);
continue;
}
}
"IOMODE","BB_WR","BB_RD"
};
char *cbus_BB[] = {"RXF","TXE","RD", "WR"};
- int i;
if (eeprom->invert)
{
No parameter checking is performed
\param ftdi pointer to ftdi_context
- \param value_name Enum of the value to query
+ \param value_name Enum of the value to set
\param value to set
\retval 0: all fine
\retval 0: All fine
\retval -1: struct ftdi_contxt or ftdi_eeprom missing
+ \retval -2: Not enough room to store eeprom
*/
int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size)
{
if (!ftdi || !(ftdi->eeprom))
ftdi_error_return(-1, "No appropriate structure");
+
+ if (!buf || size < ftdi->eeprom->size)
+ ftdi_error_return(-1, "Not enough room to store eeprom");
+
+ // Only copy up to FTDI_MAX_EEPROM_SIZE bytes
+ if (size > FTDI_MAX_EEPROM_SIZE)
+ size = FTDI_MAX_EEPROM_SIZE;
+
memcpy(buf, ftdi->eeprom->buf, size);
+
return 0;
}