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 "infnoise.h"
|
||||||
#include "KeccakF-1600-interface.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
|
// 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
|
// 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
|
// per byte read. Feed bits from the INM to the health checker. Return the expected
|
||||||
@@ -142,13 +139,16 @@ static bool listUSBDevices(struct ftdi_context *ftdic) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (curdev = devlist; curdev != NULL; i++) {
|
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);
|
rc = ftdi_usb_get_strings(ftdic, curdev->dev, manufacturer, 128, description, 128, serial, 128);
|
||||||
if (rc < 0) {
|
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));
|
fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", rc, ftdi_get_error_string(ftdic));
|
||||||
return false;
|
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;
|
curdev = curdev->next;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -170,9 +170,9 @@ static bool initializeUSB(struct ftdi_context *ftdic, char **message, char *seri
|
|||||||
// only one found, or no serial given
|
// only one found, or no serial given
|
||||||
if (rc >= 0) {
|
if (rc >= 0) {
|
||||||
if (serial == NULL) {
|
if (serial == NULL) {
|
||||||
// only one found, or no serial given
|
// more than one found AND no serial given
|
||||||
if (rc >= 1) {
|
if (rc >= 2) {
|
||||||
fprintf(stderr,"Multiple Infnoise TRNGs found. No serial specfified, so using the first one");
|
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 (ftdi_usb_open(ftdic, INFNOISE_VENDOR_ID, INFNOISE_PRODUCT_ID) < 0) {
|
||||||
if(!isSuperUser()) {
|
if(!isSuperUser()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user