]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
a649576d66021eeb2fb1ac062482d9822a039d43
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
17 #include <readline/readline.h>
18 #include <readline/history.h>
19 //#include "proxusb.h"
20 #include "proxmark3.h"
27 static serial_port sp
;
29 void SendCommand(UsbCommand
*c
) {
31 printf("Sending %d bytes\n", sizeof(UsbCommand
));
33 if (!uart_send(sp
,(byte_t
*)c
,sizeof(UsbCommand
))) {
34 ERR("Sending bytes to proxmark failed");
42 struct main_loop_arg
{
44 char *script_cmds_file
;
47 //static void *usb_receiver(void *targ) {
48 // struct receiver_arg *arg = (struct receiver_arg*)targ;
52 // if (ReceiveCommandPoll(&cmdbuf)) {
53 // UsbCommandReceived(&cmdbuf);
58 // pthread_exit(NULL);
64 static void *uart_receiver(void *targ
) {
65 struct receiver_arg
*arg
= (struct receiver_arg
*)targ
;
70 rxlen
= sizeof(UsbCommand
);
71 if (uart_receive(sp
,rx
,&rxlen
)) {
72 if ((rxlen
% sizeof(UsbCommand
)) != 0) {
73 PrintAndLog("ERROR: received %zd bytes, which does not seem to be one or more command(s)\n",rxlen
);
76 cmd_count
= rxlen
/ sizeof(UsbCommand
);
77 // printf("received %zd bytes, which represents %zd commands\n",rxlen, cmd_count);
78 for (size_t i
=0; i
<cmd_count
; i
++) {
79 UsbCommandReceived((UsbCommand
*)(rx
+(i
*sizeof(UsbCommand
))));
89 static void *main_loop(void *targ
) {
90 struct main_loop_arg
*arg
= (struct main_loop_arg
*)targ
;
91 struct receiver_arg rarg
;
93 pthread_t reader_thread
;
95 if (arg
->usb_present
== 1) {
97 // pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
98 pthread_create(&reader_thread
, NULL
, &uart_receiver
, &rarg
);
101 FILE *script_file
= NULL
;
102 char script_cmd_buf
[256];
104 if (arg
->script_cmds_file
)
106 script_file
= fopen(arg
->script_cmds_file
, "r");
109 printf("using 'scripting' commands file %s\n", arg
->script_cmds_file
);
113 read_history(".history");
116 // If there is a script file
119 if (!fgets(script_cmd_buf
, sizeof(script_cmd_buf
), script_file
))
127 nl
= strrchr(script_cmd_buf
, '\r');
129 nl
= strrchr(script_cmd_buf
, '\n');
132 if ((cmd
= (char*) malloc(strlen(script_cmd_buf
))) != NULL
)
134 memset(cmd
, 0, strlen(script_cmd_buf
));
135 strcpy(cmd
, script_cmd_buf
);
143 cmd
= readline(PROXPROMPT
);
147 while(cmd
[strlen(cmd
) - 1] == ' ')
148 cmd
[strlen(cmd
) - 1] = 0x00;
150 if (cmd
[0] != 0x00) {
151 if (strncmp(cmd
, "quit", 4) == 0) {
155 CommandReceived(cmd
);
165 write_history(".history");
167 if (arg
->usb_present
== 1) {
169 pthread_join(reader_thread
, NULL
);
183 int main(int argc
, char* argv
[]) {
186 printf("syntax: %s <port>\n\n",argv
[0]);
190 // Make sure to initialize
191 struct main_loop_arg marg
= {
193 .script_cmds_file
= NULL
195 pthread_t main_loop_t
;
199 if (!OpenProxmark(1)) {
200 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
201 marg.usb_present = 0;
204 marg.usb_present = 1;
208 sp
= uart_open(argv
[1]);
209 if (sp
== INVALID_SERIAL_PORT
) {
210 printf("ERROR: invalid serial port\n");
211 marg
.usb_present
= 0;
214 marg
.usb_present
= 1;
218 // If the user passed the filename of the 'script' to execute, get it
219 if (argc
> 2 && argv
[2]) {
220 marg
.script_cmds_file
= argv
[2];
223 pthread_create(&main_loop_t
, NULL
, &main_loop
, &marg
);
224 InitGraphics(argc
, argv
);
228 pthread_join(main_loop_t
, NULL
);
230 // if (marg.usb_present == 1) {