]> git.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
Removing windows specific code. Everything now compile and work the same for the...
[proxmark3-svn] / client / proxmark3.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <pthread.h>
5 #include <readline/readline.h>
6 #include <readline/history.h>
7 #include "proxusb.h"
8 #include "proxmark3.h"
9 #include "proxgui.h"
10 #include "cmdmain.h"
11
12 struct usb_receiver_arg
13 {
14 int run;
15 };
16
17 struct main_loop_arg
18 {
19 int usb_present;
20 };
21
22 static void *usb_receiver(void *targ)
23 {
24 struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
25 UsbCommand cmdbuf;
26
27 while (arg->run) {
28 if (ReceiveCommandPoll(&cmdbuf)) {
29 for (int i = 0; i < strlen(PROXPROMPT); i++)
30 putchar(0x08);
31 UsbCommandReceived(&cmdbuf);
32 printf(PROXPROMPT);
33 fflush(NULL);
34 }
35 }
36
37 pthread_exit(NULL);
38 return NULL;
39 }
40
41 static void *main_loop(void *targ)
42 {
43 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
44 struct usb_receiver_arg rarg;
45 char *cmd = NULL;
46 pthread_t reader_thread;
47
48 if (arg->usb_present == 1) {
49 rarg.run=1;
50 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
51 }
52
53 while(1) {
54 cmd = readline(PROXPROMPT);
55 if (cmd) {
56 if (cmd[0] != 0x00) {
57 CommandReceived(cmd);
58 add_history(cmd);
59 }
60 free(cmd);
61 } else {
62 printf("\n");
63 break;
64 }
65 }
66
67 if (arg->usb_present == 1) {
68 rarg.run = 0;
69 pthread_join(reader_thread, NULL);
70 }
71
72 ExitGraphics();
73 pthread_exit(NULL);
74 return NULL;
75 }
76
77 int main(int argc, char **argv)
78 {
79 struct main_loop_arg marg;
80 pthread_t main_loop_t;
81 usb_init();
82
83 if (!OpenProxmark(1)) {
84 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
85 marg.usb_present = 0;
86 offline = 1;
87 } else {
88 marg.usb_present = 1;
89 offline = 0;
90 }
91
92 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
93 InitGraphics(argc, argv);
94
95 MainGraphics();
96
97 pthread_join(main_loop_t, NULL);
98
99 if (marg.usb_present == 1) {
100 CloseProxmark();
101 }
102 return 0;
103 }
Impressum, Datenschutz