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