]> git.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
setting svn:eol-style=native on files, part 1
[proxmark3-svn] / client / proxmark3.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Main binary
9 //-----------------------------------------------------------------------------
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <pthread.h>
15 #include <readline/readline.h>
16 #include <readline/history.h>
17 #include "proxusb.h"
18 #include "proxmark3.h"
19 #include "proxgui.h"
20 #include "cmdmain.h"
21
22 struct usb_receiver_arg
23 {
24 int run;
25 };
26
27 struct main_loop_arg
28 {
29 int usb_present;
30 };
31
32 static void *usb_receiver(void *targ)
33 {
34 struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
35 UsbCommand cmdbuf;
36
37 while (arg->run) {
38 if (ReceiveCommandPoll(&cmdbuf)) {
39 for (int i = 0; i < strlen(PROXPROMPT); i++)
40 putchar(0x08);
41 UsbCommandReceived(&cmdbuf);
42 printf(PROXPROMPT);
43 fflush(NULL);
44 }
45 }
46
47 pthread_exit(NULL);
48 return NULL;
49 }
50
51 static void *main_loop(void *targ)
52 {
53 struct main_loop_arg *arg = (struct main_loop_arg*)targ;
54 struct usb_receiver_arg rarg;
55 char *cmd = NULL;
56 pthread_t reader_thread;
57
58 if (arg->usb_present == 1) {
59 rarg.run=1;
60 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
61 }
62
63 while(1) {
64 cmd = readline(PROXPROMPT);
65 if (cmd) {
66 if (cmd[0] != 0x00) {
67 CommandReceived(cmd);
68 add_history(cmd);
69 }
70 free(cmd);
71 } else {
72 printf("\n");
73 break;
74 }
75 }
76
77 if (arg->usb_present == 1) {
78 rarg.run = 0;
79 pthread_join(reader_thread, NULL);
80 }
81
82 ExitGraphics();
83 pthread_exit(NULL);
84 return NULL;
85 }
86
87 int main(int argc, char **argv)
88 {
89 struct main_loop_arg marg;
90 pthread_t main_loop_t;
91 usb_init();
92
93 if (!OpenProxmark(1)) {
94 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
95 marg.usb_present = 0;
96 offline = 1;
97 } else {
98 marg.usb_present = 1;
99 offline = 0;
100 }
101
102 pthread_create(&main_loop_t, NULL, &main_loop, &marg);
103 InitGraphics(argc, argv);
104
105 MainGraphics();
106
107 pthread_join(main_loop_t, NULL);
108
109 if (marg.usb_present == 1) {
110 CloseProxmark();
111 }
112 return 0;
113 }
Impressum, Datenschutz