]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
Minor fix to armsrc ldscript
[proxmark3-svn] / client / proxmark3.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 //
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
7 // the license.
8 //-----------------------------------------------------------------------------
9 // Main binary
10 //-----------------------------------------------------------------------------
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <pthread.h>
16 #include <readline/readline.h>
17 #include <readline/history.h>
18 #include "proxusb.h"
19 #include "proxmark3.h"
20 #include "proxgui.h"
21 #include "cmdmain.h"
22
23 struct usb_receiver_arg
24 {
25 int run;
26 };
27
28 struct main_loop_arg
29 {
30 int usb_present;
31 };
32
33 static void *usb_receiver(void *targ)
34 {
35 struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
36 UsbCommand cmdbuf;
37
38 while (arg->run) {
39 if (ReceiveCommandPoll(&cmdbuf)) {
40 for (int i = 0; i < strlen(PROXPROMPT); i++)
41 putchar(0x08);
42 UsbCommandReceived(&cmdbuf);
43 printf(PROXPROMPT);
44 fflush(NULL);
45 }
46 }
47
48 pthread_exit(NULL);
49 return NULL;
50 }
51
52 static void *main_loop(void *targ)
53 {
54 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
55 struct usb_receiver_arg rarg;
56 char *cmd = NULL;
57 pthread_t reader_thread;
58
59 if (arg->usb_present == 1) {
60 rarg.run=1;
61 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
62 }
63
64 while(1) {
65 cmd = readline(PROXPROMPT);
66 if (cmd) {
67 if (cmd[0] != 0x00) {
68 CommandReceived(cmd);
69 add_history(cmd);
70 }
71 free(cmd);
72 } else {
73 printf("\n");
74 break;
75 }
76 }
77
78 if (arg->usb_present == 1) {
79 rarg.run = 0;
80 pthread_join(reader_thread, NULL);
81 }
82
83 ExitGraphics();
84 pthread_exit(NULL);
85 return NULL;
86 }
87
88 int main(int argc, char **argv)
89 {
90 struct main_loop_arg marg;
91 pthread_t main_loop_t;
92 usb_init();
93
94 if (!OpenProxmark(1)) {
95 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
96 marg.usb_present = 0;
97 offline = 1;
98 } else {
99 marg.usb_present = 1;
100 offline = 0;
101 }
102
103 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
104 InitGraphics(argc, argv);
105
106 MainGraphics();
107
108 pthread_join(main_loop_t, NULL);
109
110 if (marg.usb_present == 1) {
111 CloseProxmark();
112 }
113 return 0;
114 }
Impressum, Datenschutz