]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/hid-flasher/proxusb.c
ADD: `analyse nuid` - generates NUID 4byte from a UID 7byte. Mifare Classic Ev1...
[proxmark3-svn] / client / hid-flasher / proxusb.c
index 3c2b20b4c13fdf6ffc182ff24a0a155b2dd903f0..300333783bdc2c2c48bc7ed900ef84fc433ff1da 100644 (file)
@@ -111,70 +111,76 @@ void ReceiveCommand(UsbCommand *c)
 
 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();
-
-  busses = usb_get_busses();
-
-  for (bus = busses; bus; bus = bus->next) {
-    struct usb_device *dev;
-    
-    for (dev = bus->devices; dev; dev = dev->next) {
-      struct usb_device_descriptor *desc = &(dev->descriptor);
-
-      if ((desc->idProduct == 0x4b8f) && (desc->idVendor == 0x9ac4)) {
-        handle = usb_open(dev);
-        if (!handle) {
-          if (verbose)
-            fprintf(stderr, "open fabiled: %s!\n", usb_strerror());
-          //return NULL;
-          continue;
-        }
-        *iface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber;
-
-        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;
+       struct usb_bus *busses, *bus;
+       usb_dev_handle *handle = NULL;
+       struct prox_unit units[50];
+       int iUnit = 0;
+
+       usb_find_busses();
+       usb_find_devices();
+
+       busses = usb_get_busses();
+
+       for (bus = busses; bus; bus = bus->next) {
+               struct usb_device *dev;
+
+               for (dev = bus->devices; dev; dev = dev->next) {
+                       struct usb_device_descriptor *desc = &(dev->descriptor);
+
+                       if ((desc->idProduct == 0x4b8f) && (desc->idVendor == 0x9ac4)) {
+                               handle = usb_open(dev);
+                               if (!handle) {
+                                       if (verbose)
+                                               fprintf(stderr, "open fabiled: %s!\n", usb_strerror());
+                                       //return NULL;
+                                       continue;
+                               }
+                               *iface = dev->config[0].interface[0].altsetting[0].bInterfaceNumber;
+
+                               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? ");
+                               int res = fscanf(stdin, "%d", &iSelection);
+                               if ( res != 1 ) {
+                                       fprintf(stderr, "Input parse error");
+                                       fflush(stderr);
+                                       abort();
+                               }
+                       }
+               }
+               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;
 }
 
 usb_dev_handle* OpenProxmark(int verbose)
Impressum, Datenschutz