#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
+#include <pthread.h>
#include "proxmark3.h"
#include "util.h"
#include "util_posix.h"
#include "flash.h"
-#include "uart.h"
+#include "comms.h"
#include "usb_cmd.h"
-
-#ifdef _WIN32
-# define unlink(x)
-#else
-# include <unistd.h>
-#endif
+#include "uart.h"
void cmd_debug(UsbCommand* UC) {
// Debug
printf("...\n");
}
-void SendCommand(UsbCommand* txcmd) {
-// printf("send: ");
-// cmd_debug(txcmd);
- if (!uart_send(sp,(uint8_t*)txcmd,sizeof(UsbCommand))) {
- printf("Sending bytes to proxmark failed\n");
- exit(1);
- }
-}
-
-void ReceiveCommand(UsbCommand* rxcmd) {
- uint8_t* prxcmd = (uint8_t*)rxcmd;
- uint8_t* prx = prxcmd;
- size_t rxlen;
- while (true) {
- if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-prxcmd), &rxlen)) {
- prx += rxlen;
- if ((prx-prxcmd) >= sizeof(UsbCommand)) {
- return;
- }
- }
- }
-}
-
static void usage(char *argv0)
{
fprintf(stderr, "Usage: %s <port> [-b] image.elf [image.elf...]\n\n", argv0);
int main(int argc, char **argv)
{
- int can_write_bl = 0;
+ int can_write_bl = false;
int num_files = 0;
int res;
flash_file_t files[MAX_FILES];
for (int i = 2; i < argc; i++) {
if (argv[i][0] == '-') {
if (!strcmp(argv[i], "-b")) {
- can_write_bl = 1;
+ can_write_bl = true;
} else {
usage(argv[0]);
return -1;
char* serial_port_name = argv[1];
- fprintf(stderr,"Waiting for Proxmark to appear on %s", serial_port_name);
- do {
- msleep(1000);
- fprintf(stderr, ".");
- } while (!OpenProxmark(0, serial_port_name));
- fprintf(stderr," Found.\n");
+ if (!OpenProxmark(serial_port_name, true, 120)) { // wait for 2 minutes
+ fprintf(stderr, "Could not find Proxmark on %s.\n\n", serial_port_name);
+ return -1;
+ } else {
+ fprintf(stderr," Found.\n");
+ }
res = flash_start_flashing(can_write_bl, serial_port_name);
if (res < 0)
if (res < 0)
return -1;
- CloseProxmark(serial_port_name);
+ // Stop the command thread.
+ CloseProxmark();
fprintf(stderr, "All done.\n\n");
fprintf(stderr, "Have a nice day!\n");