X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/4cd41f34ead6351f3b0a897453b25c036021c53f..e4da8ed0bbcd6352a3aba257b084849443882e59:/client/proxusb.c diff --git a/client/proxusb.c b/client/proxusb.c index b71cffc1..3c2b20b4 100644 --- a/client/proxusb.c +++ b/client/proxusb.c @@ -1,5 +1,17 @@ +//----------------------------------------------------------------------------- +// Copyright (C) 2009 Michael Gernoth +// Copyright (C) 2010 iZsh +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// USB utilities +//----------------------------------------------------------------------------- + #include #include +#include #include #include #include @@ -101,6 +113,8 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface) { struct usb_bus *busses, *bus; usb_dev_handle *handle = NULL; + struct prox_unit units[50]; + int iUnit = 0; usb_find_busses(); usb_find_devices(); @@ -117,14 +131,47 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface) handle = usb_open(dev); if (!handle) { if (verbose) - fprintf(stderr, "open failed: %s!\n", usb_strerror()); - return NULL; + fprintf(stderr, "open fabiled: %s!\n", usb_strerror()); + //return NULL; + continue; } *iface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber; - return handle; + + struct prox_unit unit = {handle, {0}}; + usb_get_string_simple(handle, desc->iSerialNumber, unit.serial_number, sizeof(unit.serial_number)); + units[iUnit++] = unit; + + //return handle; } + } + } + if (iUnit > 0) { + int iSelection = 0; + + fprintf(stdout, "\nConnected units:\n"); + + for (int i = 0; i < iUnit; i++) { + struct usb_device * dev = usb_device(units[i].handle); + fprintf(stdout, "\t%d. SN: %s [%s/%s]\n", i+1, units[i].serial_number, dev->bus->dirname, dev->filename); + } + if (iUnit > 1) { + while (iSelection < 1 || iSelection > iUnit) { + fprintf(stdout, "Which unit do you want to connect to? "); + fscanf(stdin, "%d", &iSelection); + } + } + else + iSelection = 1; + iSelection --; + + for (int i = 0; i < iUnit; i++) { + if (iSelection == i) continue; + usb_close(units[i].handle); + units[i].handle = NULL; } + + return units[iSelection].handle; } return NULL; @@ -136,15 +183,6 @@ usb_dev_handle* OpenProxmark(int verbose) usb_dev_handle *handle = NULL; unsigned int iface; -#ifdef __linux__ - handle = findProxmark(verbose, &iface); - if (!handle) - return NULL; - - /* Whatever... */ - usb_reset(handle); -#endif - handle = findProxmark(verbose, &iface); if (!handle) return NULL;