]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/proxmark3.c
Removing windows specific code. Everything now compile and work the same for the...
[proxmark3-svn] / client / proxmark3.c
CommitLineData
6658905f 1#include <stdio.h>
590f8ff9 2#include <stdlib.h>
6658905f 3#include <string.h>
7fe9b0b7 4#include <pthread.h>
6658905f 5#include <readline/readline.h>
6#include <readline/history.h>
7fe9b0b7 7#include "proxusb.h"
6658905f 8#include "proxmark3.h"
9#include "proxgui.h"
7fe9b0b7 10#include "cmdmain.h"
6658905f 11
7fe9b0b7 12struct usb_receiver_arg
13{
14 int run;
6658905f 15};
16
7fe9b0b7 17struct main_loop_arg
18{
19 int usb_present;
a60612db 20};
21
7fe9b0b7 22static 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);
4cd41f34 38 return NULL;
6658905f 39}
40
41static void *main_loop(void *targ)
42{
7fe9b0b7 43 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
44 struct usb_receiver_arg rarg;
45 char *cmd = NULL;
46 pthread_t reader_thread;
47
48 if (arg->usb_present == 1) {
49 rarg.run=1;
50 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
51 }
52
53 while(1) {
54 cmd = readline(PROXPROMPT);
55 if (cmd) {
56 if (cmd[0] != 0x00) {
57 CommandReceived(cmd);
58 add_history(cmd);
59 }
60 free(cmd);
61 } else {
62 printf("\n");
63 break;
64 }
65 }
66
67 if (arg->usb_present == 1) {
68 rarg.run = 0;
69 pthread_join(reader_thread, NULL);
70 }
71
72 ExitGraphics();
73 pthread_exit(NULL);
4cd41f34 74 return NULL;
6658905f 75}
76
77int main(int argc, char **argv)
78{
7fe9b0b7 79 struct main_loop_arg marg;
80 pthread_t main_loop_t;
81 usb_init();
82
83 if (!OpenProxmark(1)) {
84 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
85 marg.usb_present = 0;
86 offline = 1;
87 } else {
88 marg.usb_present = 1;
89 offline = 0;
90 }
91
92 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
93 InitGraphics(argc, argv);
94
95 MainGraphics();
96
97 pthread_join(main_loop_t, NULL);
98
99 if (marg.usb_present == 1) {
100 CloseProxmark();
101 }
102 return 0;
6658905f 103}
Impressum, Datenschutz