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