]> git.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
Clean up data types, some header cleanup, etc.
[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 }
39
40 static void *main_loop(void *targ)
41 {
42 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
43 struct usb_receiver_arg rarg;
44 char *cmd = NULL;
45 pthread_t reader_thread;
46
47 if (arg->usb_present == 1) {
48 rarg.run=1;
49 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
50 }
51
52 while(1) {
53 cmd = readline(PROXPROMPT);
54 if (cmd) {
55 if (cmd[0] != 0x00) {
56 CommandReceived(cmd);
57 add_history(cmd);
58 }
59 free(cmd);
60 } else {
61 printf("\n");
62 break;
63 }
64 }
65
66 if (arg->usb_present == 1) {
67 rarg.run = 0;
68 pthread_join(reader_thread, NULL);
69 }
70
71 ExitGraphics();
72 pthread_exit(NULL);
73 }
74
75 int main(int argc, char **argv)
76 {
77 struct main_loop_arg marg;
78 pthread_t main_loop_t;
79 usb_init();
80
81 if (!OpenProxmark(1)) {
82 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
83 marg.usb_present = 0;
84 offline = 1;
85 } else {
86 marg.usb_present = 1;
87 offline = 0;
88 }
89
90 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
91 InitGraphics(argc, argv);
92
93 MainGraphics();
94
95 pthread_join(main_loop_t, NULL);
96
97 if (marg.usb_present == 1) {
98 CloseProxmark();
99 }
100 return 0;
101 }
Impressum, Datenschutz