mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
|
@ -22,80 +22,80 @@ unsigned char error_occured = 0;
|
|||
|
||||
void SendCommand(UsbCommand *c)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
#if 0
|
||||
printf("Sending %d bytes\n", sizeof(UsbCommand));
|
||||
printf("Sending %d bytes\n", sizeof(UsbCommand));
|
||||
#endif
|
||||
|
||||
ret = usb_bulk_write(devh, 0x01, (char*)c, sizeof(UsbCommand), 1000);
|
||||
if (ret<0) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return;
|
||||
ret = usb_bulk_write(devh, 0x01, (char *)c, sizeof(UsbCommand), 1000);
|
||||
if (ret < 0) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "write failed: %s!\nTrying to reopen device...\n",
|
||||
usb_strerror());
|
||||
fprintf(stderr, "write failed: %s!\nTrying to reopen device...\n",
|
||||
usb_strerror());
|
||||
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while (!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
while(!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool ReceiveCommandPoll(UsbCommand *c)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
memset(c, 0, sizeof (UsbCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char*)c, sizeof(UsbCommand), 500);
|
||||
if (ret<0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return false;
|
||||
memset(c, 0, sizeof(UsbCommand));
|
||||
ret = usb_bulk_read(devh, 0x82, (char *)c, sizeof(UsbCommand), 500);
|
||||
if (ret < 0) {
|
||||
if (ret != -ETIMEDOUT) {
|
||||
error_occured = 1;
|
||||
if (return_on_error)
|
||||
return false;
|
||||
|
||||
fprintf(stderr, "read failed: %s(%d)!\nTrying to reopen device...\n",
|
||||
usb_strerror(), ret);
|
||||
fprintf(stderr, "read failed: %s(%d)!\nTrying to reopen device...\n",
|
||||
usb_strerror(), ret);
|
||||
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while(!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
if (devh) {
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
while (!OpenProxmark(0)) { msleep(1000); }
|
||||
printf(PROXPROMPT);
|
||||
fflush(NULL);
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (ret && (ret < sizeof(UsbCommand))) {
|
||||
fprintf(stderr, "Read only %d instead of requested %d bytes!\n",
|
||||
ret, (int)sizeof(UsbCommand));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ret && (ret < sizeof(UsbCommand))) {
|
||||
fprintf(stderr, "Read only %d instead of requested %d bytes!\n",
|
||||
ret, (int)sizeof(UsbCommand));
|
||||
}
|
||||
}
|
||||
|
||||
return ret > 0;
|
||||
return ret > 0;
|
||||
}
|
||||
|
||||
void ReceiveCommand(UsbCommand *c)
|
||||
{
|
||||
// printf("%s()\n", __FUNCTION__);
|
||||
int retval = 0;
|
||||
do {
|
||||
retval = ReceiveCommandPoll(c);
|
||||
if (retval != 1) printf("ReceiveCommandPoll returned %d\n", retval);
|
||||
} while(retval<0);
|
||||
int retval = 0;
|
||||
do {
|
||||
retval = ReceiveCommandPoll(c);
|
||||
if (retval != 1) printf("ReceiveCommandPoll returned %d\n", retval);
|
||||
} while (retval < 0);
|
||||
// printf("recv %x\n", c->cmd);
|
||||
}
|
||||
|
||||
usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
||||
usb_dev_handle *findProxmark(int verbose, unsigned int *iface)
|
||||
{
|
||||
struct usb_bus *busses, *bus;
|
||||
usb_dev_handle *handle = NULL;
|
||||
|
@ -138,21 +138,20 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
|||
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);
|
||||
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 ) {
|
||||
if (res != 1) {
|
||||
fprintf(stderr, "Input parse error");
|
||||
fflush(stderr);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
iSelection = 1;
|
||||
}
|
||||
|
||||
|
@ -169,46 +168,46 @@ usb_dev_handle* findProxmark(int verbose, unsigned int *iface)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
usb_dev_handle* OpenProxmark(int verbose)
|
||||
usb_dev_handle *OpenProxmark(int verbose)
|
||||
{
|
||||
int ret;
|
||||
usb_dev_handle *handle = NULL;
|
||||
unsigned int iface;
|
||||
int ret;
|
||||
usb_dev_handle *handle = NULL;
|
||||
unsigned int iface;
|
||||
|
||||
handle = findProxmark(verbose, &iface);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
handle = findProxmark(verbose, &iface);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
#ifdef __linux__
|
||||
/* detach kernel driver first */
|
||||
ret = usb_detach_kernel_driver_np(handle, iface);
|
||||
/* don't complain if no driver attached */
|
||||
if (ret<0 && ret != -61 && verbose)
|
||||
fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror());
|
||||
/* detach kernel driver first */
|
||||
ret = usb_detach_kernel_driver_np(handle, iface);
|
||||
/* don't complain if no driver attached */
|
||||
if (ret < 0 && ret != -61 && verbose)
|
||||
fprintf(stderr, "detach kernel driver failed: (%d) %s!\n", ret, usb_strerror());
|
||||
#endif
|
||||
|
||||
// Needed for Windows. Optional for Mac OS and Linux
|
||||
ret = usb_set_configuration(handle, 1);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "configuration set failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
// Needed for Windows. Optional for Mac OS and Linux
|
||||
ret = usb_set_configuration(handle, 1);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "configuration set failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = usb_claim_interface(handle, iface);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "claim failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
claimed_iface = iface;
|
||||
devh = handle;
|
||||
return handle;
|
||||
ret = usb_claim_interface(handle, iface);
|
||||
if (ret < 0) {
|
||||
if (verbose)
|
||||
fprintf(stderr, "claim failed: %s!\n", usb_strerror());
|
||||
return NULL;
|
||||
}
|
||||
claimed_iface = iface;
|
||||
devh = handle;
|
||||
return handle;
|
||||
}
|
||||
|
||||
void CloseProxmark(void)
|
||||
{
|
||||
usb_release_interface(devh, claimed_iface);
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
usb_release_interface(devh, claimed_iface);
|
||||
usb_close(devh);
|
||||
devh = NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue