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