Merge pull request #37 from manuel-domke/refactoring
improved error handling for listing devices and nicer output
This commit is contained in:
		| @@ -17,9 +17,6 @@ | ||||
| #include "infnoise.h" | ||||
| #include "KeccakF-1600-interface.h" | ||||
|  | ||||
| #define VEND_ID 0x0403 | ||||
| #define PROD_ID 0x6015 | ||||
|  | ||||
| // Extract the INM output from the data received.  Basically, either COMP1 or COMP2 | ||||
| // changes, not both, so alternate reading bits from them.  We get 1 INM bit of output | ||||
| // per byte read.  Feed bits from the INM to the health checker.  Return the expected | ||||
| @@ -135,20 +132,23 @@ static bool listUSBDevices(struct ftdi_context *ftdic) { | ||||
|     int rc = ftdi_usb_find_all(ftdic, &devlist, INFNOISE_VENDOR_ID, INFNOISE_PRODUCT_ID); | ||||
|  | ||||
|     if (rc < 0) { | ||||
|         if(!isSuperUser()) { | ||||
|         if (!isSuperUser()) { | ||||
|             fprintf(stderr, "Can't find Infinite Noise Multiplier.  Try running as super user?\n"); | ||||
|         } else { | ||||
|             fprintf(stderr, "Can't find Infinite Noise Multiplier\n"); | ||||
|         } | ||||
|     } | ||||
|     for (curdev = devlist; curdev != NULL; i++) { | ||||
|        	printf("Checking device: %d\n", i); | ||||
|         printf("Device: %d, ", i); | ||||
|         rc = ftdi_usb_get_strings(ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128); | ||||
|         if (rc < 0) { | ||||
|             if (!isSuperUser()) { | ||||
|                 fprintf(stderr, "Can't find Infinite Noise Multiplier.  Try running as super user?\n"); | ||||
|             } | ||||
|             fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", rc, ftdi_get_error_string(ftdic)); | ||||
| 	    return false; | ||||
|        	} | ||||
|         printf("Manufacturer: %s, Description: %s, Serial: %s\n\n", manufacturer, description, serial); | ||||
|         printf("Manufacturer: %s, Description: %s, Serial: %s\n", manufacturer, description, serial); | ||||
|        	curdev = curdev->next; | ||||
|     } | ||||
|     return true; | ||||
| @@ -170,9 +170,9 @@ static bool initializeUSB(struct ftdi_context *ftdic, char **message, char *seri | ||||
|     // only one found, or no serial given | ||||
|     if (rc >= 0) { | ||||
| 	if (serial == NULL) { | ||||
|             // only one found, or no serial given | ||||
|             if (rc >= 1) { | ||||
| 		fprintf(stderr,"Multiple Infnoise TRNGs found. No serial specfified, so using the first one"); | ||||
|             // more than one found AND no serial given | ||||
|             if (rc >= 2) { | ||||
| 		fprintf(stderr,"Multiple Infnoise TRNGs found and serial not specified, using the first one!\n"); | ||||
|             } | ||||
|             if (ftdi_usb_open(ftdic, INFNOISE_VENDOR_ID, INFNOISE_PRODUCT_ID) < 0) { | ||||
|                 if(!isSuperUser()) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user