diff options
Diffstat (limited to 'src/devices.c')
-rw-r--r-- | src/devices.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/devices.c b/src/devices.c index 538dc9e..0739905 100644 --- a/src/devices.c +++ b/src/devices.c @@ -24,6 +24,7 @@ #include <stdlib.h> struct devices supported_devices[SUPPORTED_DEVICES] = { + { "FFFF", 0x000, 0x0000, 0x0000 }, // dummy { "unkn", 0x421, 0x3f00, 0x0000 }, // probably a development board { "n770", 0x421, 0x0105, 0x0001 }, // my n770 { "n800", 0x421, 0x04c3, 0x0001 }, // a n800 @@ -31,17 +32,22 @@ struct devices supported_devices[SUPPORTED_DEVICES] = { { 0 } }; +/** Returns 0 when no device was found and a positive + * non-zero value when one was found. + * + * The return value is the index into the supported_devices + * array which denotes the device which was found. + */ int is_valid_device(struct usb_device_descriptor *udd) { int i; - struct devices ptr = supported_devices[0]; + struct devices ptr = supported_devices[1]; - for(i=0 ; ptr.vendor_id; ptr = supported_devices[++i]) + for(i=1 ; ptr.vendor_id; ptr = supported_devices[++i]) if ((udd->idVendor == ptr.vendor_id) && (udd->idProduct == ptr.product_id)) { - printf("found %s (%04x:%04x)\n", - ptr.name, ptr.vendor_id, ptr.product_id); - return 1; + D printf("found %s\n", supported_devices[i]); + return i; } return 0; @@ -50,23 +56,29 @@ int is_valid_device(struct usb_device_descriptor *udd) void list_valid_devices() { int i; - struct devices ptr = supported_devices[0]; + struct devices ptr = supported_devices[1]; - for(i=0; ptr.vendor_id; ptr = supported_devices[++i]) + for(i=1; ptr.vendor_id; ptr = supported_devices[++i]) printf("%04x:%04x %s\n", ptr.vendor_id, ptr.product_id, ptr.name); } -int usb_device_found(struct usb_device_descriptor *udd) +int usb_device_found(struct usb_device_descriptor *udd, struct devices *it_device) { + struct usb_bus *bus; + int dev_index = 0; + if (usb_find_busses() < 0) { - fprintf(stderr, "error: no usb busses found.\n"); + fprintf(stderr, "\nerror: no usb busses found.\n"); exit(1); } else { - if (usb_find_devices() < 0) { - fprintf(stderr, "error: no devices found.\n"); + switch(usb_find_devices()) { + case -1: + fprintf(stderr, "\nerror: no devices found.\n"); + exit(1); + case 0: + fprintf(stderr, "\noops: no permission to usb. got root?\n"); exit(1); - } else { - struct usb_bus *bus; + default: for (bus = usb_busses; bus; bus = bus->next) { struct usb_device *dev = bus->devices; D printf("bus: \n"); @@ -75,8 +87,9 @@ int usb_device_found(struct usb_device_descriptor *udd) D printf(" dev (%s) - ", dev->filename); D printf("vendor: %04x product: %04x\n", udd->idVendor, udd->idProduct); - if (is_valid_device(udd)) { + if ((dev_index = is_valid_device(udd))) { device = dev; + *it_device = supported_devices[dev_index]; return 1; } } |