]> git.zerfleddert.de Git - proxmark3-svn/blame - client/proxmark3.c
setting svn:eol-style=native on files, part 1
[proxmark3-svn] / client / proxmark3.c
CommitLineData
a553f267 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
6658905f 11#include <stdio.h>
590f8ff9 12#include <stdlib.h>
6658905f 13#include <string.h>
7fe9b0b7 14#include <pthread.h>
6658905f 15#include <readline/readline.h>
16#include <readline/history.h>
7fe9b0b7 17#include "proxusb.h"
6658905f 18#include "proxmark3.h"
19#include "proxgui.h"
7fe9b0b7 20#include "cmdmain.h"
6658905f 21
7fe9b0b7 22struct usb_receiver_arg
23{
24 int run;
6658905f 25};
26
7fe9b0b7 27struct main_loop_arg
28{
29 int usb_present;
a60612db 30};
31
7fe9b0b7 32static 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);
4cd41f34 48 return NULL;
6658905f 49}
50
51static void *main_loop(void *targ)
52{
7fe9b0b7 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);
4cd41f34 84 return NULL;
6658905f 85}
86
87int main(int argc, char **argv)
88{
7fe9b0b7 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;
6658905f 113}
Impressum, Datenschutz