]>
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 | ||
cd00aa30 | 12 | #include "prox.h" |
6658905f | 13 | #include "proxmark3.h" |
14 | #include "proxgui.h" | |
15 | ||
16 | struct usb_receiver_arg { | |
17 | int run; | |
18 | }; | |
19 | ||
a60612db | 20 | struct main_loop_arg { |
21 | int usb_present; | |
22 | }; | |
23 | ||
6658905f | 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) { | |
aa81a8d3 | 29 | if (ReceiveCommandPoll(&cmdbuf)) { |
6658905f | 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 | { | |
a60612db | 46 | struct main_loop_arg *arg = (struct main_loop_arg*)targ; |
6658905f | 47 | char *cmd = NULL; |
022c8791 | 48 | pthread_t reader_thread; |
6658905f | 49 | |
022c8791 | 50 | if (arg->usb_present == 1) { |
6658905f | 51 | struct usb_receiver_arg rarg; |
6658905f | 52 | rarg.run=1; |
022c8791 | 53 | pthread_create(&reader_thread, NULL, &usb_receiver, &rarg); |
54 | } | |
55 | ||
56 | while(1) { | |
6658905f | 57 | |
022c8791 | 58 | cmd = readline(PROXPROMPT); |
6658905f | 59 | if (cmd) { |
60 | if (cmd[0] != 0x00) { | |
61 | CommandReceived(cmd); | |
62 | add_history(cmd); | |
63 | } | |
64 | free(cmd); | |
65 | } else { | |
66 | printf("\n"); | |
67 | break; | |
68 | } | |
69 | } | |
70 | ||
71 | ExitGraphics(); | |
72 | pthread_exit(NULL); | |
73 | } | |
74 | ||
75 | int main(int argc, char **argv) | |
76 | { | |
a60612db | 77 | struct main_loop_arg marg; |
6658905f | 78 | pthread_t main_loop_t; |
79 | usb_init(); | |
80 | ||
81 | if (!(devh = OpenProxmark(1))) { | |
82 | fprintf(stderr,"PROXMARK3: NOT FOUND!\n"); | |
a60612db | 83 | marg.usb_present = 0; |
d722c4ce | 84 | offline = 1; |
a60612db | 85 | } else { |
86 | marg.usb_present = 1; | |
d722c4ce | 87 | offline = 0; |
6658905f | 88 | } |
89 | ||
a60612db | 90 | pthread_create(&main_loop_t, NULL, &main_loop, &marg); |
6658905f | 91 | InitGraphics(argc, argv); |
92 | ||
93 | MainGraphics(); | |
94 | ||
95 | pthread_join(main_loop_t, NULL); | |
96 | ||
a60612db | 97 | if (marg.usb_present == 1) { |
98 | CloseProxmark(); | |
99 | } | |
6658905f | 100 | return 0; |
101 | } |