]> git.zerfleddert.de Git - proxmark3-svn/blame - linux/proxmark3.c
Initial commit for the firmware. Used the 20090306_ela version as baseline.
[proxmark3-svn] / linux / 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
12#include "translate.h"
13#include "../winsrc/prox.h"
14#include "proxmark3.h"
15#include "proxgui.h"
16
17struct usb_receiver_arg {
18 int run;
19};
20
21static void *usb_receiver(void *targ) {
22 struct usb_receiver_arg *arg = (struct usb_receiver_arg*)targ;
23 UsbCommand cmdbuf;
24
25 while(arg->run) {
26 if (ReceiveCommandP(&cmdbuf) > 0) {
27 int i;
28
29 for (i=0; i<strlen(PROXPROMPT); i++)
30 putchar(0x08);
31
32 UsbCommandReceived(&cmdbuf);
33 printf(PROXPROMPT);
34 fflush(NULL);
35 }
36 }
37
38 pthread_exit(NULL);
39}
40
41static void *main_loop(void *targ)
42{
43 char *cmd = NULL;
44
45 while(1) {
46 struct usb_receiver_arg rarg;
47 pthread_t reader_thread;
48
49 rarg.run=1;
50 pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
51
52 cmd = readline(PROXPROMPT);
53 rarg.run=0;
54 pthread_join(reader_thread, NULL);
55
56 if (cmd) {
57 if (cmd[0] != 0x00) {
58 CommandReceived(cmd);
59 add_history(cmd);
60 }
61 free(cmd);
62 } else {
63 printf("\n");
64 break;
65 }
66 }
67
68 ExitGraphics();
69 pthread_exit(NULL);
70}
71
72int main(int argc, char **argv)
73{
74 pthread_t main_loop_t;
75 usb_init();
76
77 if (!(devh = OpenProxmark(1))) {
78 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
79 exit(1);
80 }
81
82 pthread_create(&main_loop_t, NULL, &main_loop, NULL);
83 InitGraphics(argc, argv);
84
85 MainGraphics();
86
87 pthread_join(main_loop_t, NULL);
88
89 CloseProxmark();
90 return 0;
91}
Impressum, Datenschutz