Address one more compile warning / add FIXME comment for Uwe
[libftdi] / src / ftdi.c
index 895f9e1..1e92dc5 100644 (file)
@@ -95,10 +95,7 @@ int ftdi_init(struct ftdi_context *ftdi)
     ftdi->writebuffer_chunksize = 4096;
     ftdi->max_packet_size = 0;
 
-    ftdi->interface = 0;
-    ftdi->index = 0;
-    ftdi->in_ep = 0x02;
-    ftdi->out_ep = 0x81;
+    ftdi_set_interface(ftdi, INTERFACE_ANY);
     ftdi->bitbang_mode = 1; /* when bitbang is enabled this holds the number of the mode  */
 
     ftdi->error_str = NULL;
@@ -154,7 +151,10 @@ int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface)
     {
         case INTERFACE_ANY:
         case INTERFACE_A:
-            /* ftdi_usb_open_desc cares to set the right index, depending on the found chip */
+            ftdi->interface = 0;
+            ftdi->index     = INTERFACE_A;
+            ftdi->in_ep     = 0x02;
+            ftdi->out_ep    = 0x81;
             break;
         case INTERFACE_B:
             ftdi->interface = 1;
@@ -557,19 +557,6 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi, libusb_device *dev)
     else if (desc.bcdDevice == 0x800)
         ftdi->type = TYPE_4232H;
 
-    // Set default interface on dual/quad type chips
-    switch (ftdi->type)
-    {
-        case TYPE_2232C:
-        case TYPE_2232H:
-        case TYPE_4232H:
-            if (!ftdi->index)
-                ftdi->index = INTERFACE_A;
-            break;
-        default:
-            break;
-    }
-
     // Determine maximum packet size
     ftdi->max_packet_size = _ftdi_determine_max_packet_size(ftdi, dev);
 
@@ -2269,10 +2256,10 @@ int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi, char * manufacturer,
 
     \retval >=0: size of eeprom user area in bytes
     \retval -1: eeprom size (128 bytes) exceeded by custom strings
-    \retval -2: Invalid eeprom pointer
-    \retval -3: Invalid cbus function setting
-    \retval -4: Chip doesn't support invert
-    \retval -5: Chip doesn't support high current drive
+    \retval -2: Invalid eeprom or ftdi pointer
+    \retval -3: Invalid cbus function setting     (FIXME: Not in the code?)
+    \retval -4: Chip doesn't support invert       (FIXME: Not in the code?)
+    \retval -5: Chip doesn't support high current drive         (FIXME: Not in the code?)
     \retval -6: No connected EEPROM or EEPROM Type unknown
 */
 int ftdi_eeprom_build(struct ftdi_context *ftdi)
@@ -2293,7 +2280,7 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
     output = eeprom->buf;
 
     if (eeprom->chip == -1)
-        ftdi_error_return(-5,"No connected EEPROM or EEPROM type unknown");
+        ftdi_error_return(-6,"No connected EEPROM or EEPROM type unknown");
 
     if ((eeprom->chip == 0x56) || (eeprom->chip == 0x66))
         eeprom->size = 0x100;
@@ -2323,6 +2310,8 @@ int ftdi_eeprom_build(struct ftdi_context *ftdi)
         case TYPE_2232H:            // six extra config bytes + 4 bytes PnP stuff
         case TYPE_4232H:
             user_area_size = 86;
+        default:
+            user_area_size = 0;
             break;
     }
     user_area_size  -= (manufacturer_size + product_size + serial_size) * 2;
@@ -2969,8 +2958,15 @@ int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose)
                     fprintf(stdout,"C%d Function: %s\n", i,
                             cbus_mux[eeprom->cbus_function[i]]);
                 else
+                {
+                    /* FIXME for Uwe: This results in an access above array bounds.
+                       Also I couldn't find documentation about this mode.
                     fprintf(stdout,"C%d BB Function: %s\n", i,
                             cbus_BB[i]);
+                    */
+                    fprintf(stdout, "Unknown CBUS mode. Might be special mode?\n");
+                    (void)cbus_BB;
+                }
             }
         }
     }