]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/proxmark3.c
Add hf list 15 (#754)
[proxmark3-svn] / client / proxmark3.c
index fc258609a150cbf062fd26c4249c1a4b3bac5d65..6fb066e8a5dbdaf5e4b7c8bbda22eafd6f6c27b5 100644 (file)
@@ -9,6 +9,8 @@
 // Main binary
 //-----------------------------------------------------------------------------
 
+#include "proxmark3.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <readline/readline.h>
 #include <readline/history.h>
 
-#include "proxmark3.h"
 #include "util_posix.h"
 #include "proxgui.h"
 #include "cmdmain.h"
-#include "uart.h"
 #include "ui.h"
 #include "util.h"
 #include "cmdparser.h"
 #include "cmdhw.h"
 #include "whereami.h"
-
+#include "comms.h"
 
 void
 #ifdef __has_attribute
@@ -36,19 +36,16 @@ __attribute__((force_align_arg_pointer))
 #endif
 #endif
 main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
-       receiver_arg conn;
        char *cmd = NULL;
-       pthread_t reader_thread;
        bool execCommand = (script_cmd != NULL);
        bool stdinOnPipe = !isatty(STDIN_FILENO);
-       
-       memset(&conn, 0, sizeof(receiver_arg));
 
        if (usb_present) {
-               conn.run = true;
-               pthread_create(&reader_thread, NULL, &uart_receiver, &conn);
+               SetOffline(false);
                // cache Version information now:
                CmdVersion(NULL);
+       } else {
+               SetOffline(true);
        }
 
        // file with script
@@ -64,7 +61,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
 
        read_history(".history");
 
-       while (1)  {
+       while (1) {
                // If there is a script file
                if (script_file)
                {
@@ -134,11 +131,6 @@ main_loop(char *script_cmds_file, char *script_cmd, bool usb_present) {
        }
 
        write_history(".history");
-  
-       if (usb_present) {
-               conn.run = false;
-               pthread_join(reader_thread, NULL);
-       }
        
        if (script_file) {
                fclose(script_file);
@@ -235,7 +227,7 @@ int main(int argc, char* argv[]) {
                
                if(strcmp(argv[i],"-f") == 0 || strcmp(argv[i],"-flush") == 0){
                        printf("Output will be flushed after every print.\n");
-                       flushAfterWrite = 1;
+                       SetFlushAfterWrite(true);
                }
                
                if(strcmp(argv[i],"-w") == 0 || strcmp(argv[i],"-wait") == 0){
@@ -290,36 +282,9 @@ int main(int argc, char* argv[]) {
        
        // set global variables
        set_my_executable_path();
-       
-       // open uart
-       if (!waitCOMPort) {
-               sp = uart_open(argv[1]);
-       } else {
-               printf("Waiting for Proxmark to appear on %s ", argv[1]);
-               fflush(stdout);
-               int openCount = 0;
-               do {
-                       sp = uart_open(argv[1]);
-                       msleep(1000);
-                       printf(".");
-                       fflush(stdout);
-               } while(++openCount < 20 && (sp == INVALID_SERIAL_PORT || sp == CLAIMED_SERIAL_PORT));
-               printf("\n");
-       }
 
-       // check result of uart opening
-       if (sp == INVALID_SERIAL_PORT) {
-               printf("ERROR: invalid serial port\n");
-               usb_present = false;
-               offline = 1;
-       } else if (sp == CLAIMED_SERIAL_PORT) {
-               printf("ERROR: serial port is claimed by another process\n");
-               usb_present = false;
-               offline = 1;
-       } else {
-               usb_present = true;
-               offline = 0;
-       }
+       // try to open USB connection to Proxmark
+       usb_present = OpenProxmark(argv[1], waitCOMPort, 20, false);
 
 #ifdef HAVE_GUI
 #ifdef _WIN32
@@ -344,7 +309,7 @@ int main(int argc, char* argv[]) {
 
        // Clean up the port
        if (usb_present) {
-               uart_close(sp);
+               CloseProxmark();
        }
 
        exit(0);
Impressum, Datenschutz