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