]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/proxmark3.c
fix some ARM build fail
[proxmark3-svn] / client / proxmark3.c
CommitLineData
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
16struct usb_receiver_arg {
17 int run;
18};
19
a60612db 20struct main_loop_arg {
21 int usb_present;
22};
23
6658905f 24static 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
44static void *main_loop(void *targ)
45{
a60612db 46 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
6658905f 47 char *cmd = NULL;
48
49 while(1) {
50 struct usb_receiver_arg rarg;
51 pthread_t reader_thread;
52
53 rarg.run=1;
a60612db 54 if (arg->usb_present == 1) {
55 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
56 }
6658905f 57 cmd = readline(PROXPROMPT);
58 rarg.run=0;
a60612db 59 if (arg->usb_present == 1) {
60 pthread_join(reader_thread, NULL);
61 }
6658905f 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
79int main(int argc, char **argv)
80{
a60612db 81 struct main_loop_arg marg;
6658905f 82 pthread_t main_loop_t;
83 usb_init();
84
85 if (!(devh = OpenProxmark(1))) {
86 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
a60612db 87 marg.usb_present = 0;
d722c4ce 88 offline = 1;
a60612db 89 } else {
90 marg.usb_present = 1;
d722c4ce 91 offline = 0;
6658905f 92 }
93
a60612db 94 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
6658905f 95 InitGraphics(argc, argv);
96
97 MainGraphics();
98
99 pthread_join(main_loop_t, NULL);
100
a60612db 101 if (marg.usb_present == 1) {
102 CloseProxmark();
103 }
6658905f 104 return 0;
105}
Impressum, Datenschutz