]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/proxmark3.c
streamline CmdEM410xWatch
[proxmark3-svn] / client / proxmark3.c
CommitLineData
6658905f 1#include <stdio.h>
6658905f 2#include <string.h>
7fe9b0b7 3#include <pthread.h>
6658905f 4#include <readline/readline.h>
5#include <readline/history.h>
7fe9b0b7 6#include "proxusb.h"
6658905f 7#include "proxmark3.h"
8#include "proxgui.h"
7fe9b0b7 9#include "cmdmain.h"
6658905f 10
7fe9b0b7 11struct usb_receiver_arg
12{
13 int run;
6658905f 14};
15
7fe9b0b7 16struct main_loop_arg
17{
18 int usb_present;
a60612db 19};
20
7fe9b0b7 21static 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);
6658905f 37}
38
39static void *main_loop(void *targ)
40{
7fe9b0b7 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);
6658905f 72}
73
74int main(int argc, char **argv)
75{
7fe9b0b7 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;
6658905f 100}
Impressum, Datenschutz