]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/proxmark3.c
cff94903d1693e46e585f9d00fedc532fc9b67b5
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 if (uart_receive(sp
,rx
,&rxlen
)) {
71 if ((rxlen
% sizeof(UsbCommand
)) != 0) {
72 PrintAndLog("ERROR: received %zd bytes, which does not seem to be one or more command(s)\n",rxlen
);
75 cmd_count
= rxlen
/ sizeof(UsbCommand
);
76 // printf("received %zd bytes, which represents %zd commands\n",rxlen, cmd_count);
77 for (size_t i
=0; i
<cmd_count
; i
++) {
78 UsbCommandReceived((UsbCommand
*)(rx
+(i
*sizeof(UsbCommand
))));
88 static void *main_loop(void *targ
) {
89 struct main_loop_arg
*arg
= (struct main_loop_arg
*)targ
;
90 struct receiver_arg rarg
;
92 pthread_t reader_thread
;
94 if (arg
->usb_present
== 1) {
96 // pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
97 pthread_create(&reader_thread
, NULL
, &uart_receiver
, &rarg
);
100 FILE *script_file
= NULL
;
101 char script_cmd_buf
[256];
103 if (arg
->script_cmds_file
)
105 script_file
= fopen(arg
->script_cmds_file
, "r");
108 printf("using 'scripting' commands file %s\n", arg
->script_cmds_file
);
112 read_history(".history");
115 // If there is a script file
118 if (!fgets(script_cmd_buf
, sizeof(script_cmd_buf
), script_file
))
126 nl
= strrchr(script_cmd_buf
, '\r');
128 nl
= strrchr(script_cmd_buf
, '\n');
131 if ((cmd
= (char*) malloc(strlen(script_cmd_buf
))) != NULL
)
133 memset(cmd
, 0, strlen(script_cmd_buf
));
134 strcpy(cmd
, script_cmd_buf
);
142 cmd
= readline(PROXPROMPT
);
146 while(cmd
[strlen(cmd
) - 1] == ' ')
147 cmd
[strlen(cmd
) - 1] = 0x00;
149 if (cmd
[0] != 0x00) {
150 if (strncmp(cmd
, "quit", 4) == 0) {
154 CommandReceived(cmd
);
164 write_history(".history");
166 if (arg
->usb_present
== 1) {
168 pthread_join(reader_thread
, NULL
);
182 int main(int argc
, char* argv
[]) {
185 printf("syntax: %s <port>\n\n",argv
[0]);
189 // Make sure to initialize
190 struct main_loop_arg marg
= {
192 .script_cmds_file
= NULL
194 pthread_t main_loop_t
;
198 if (!OpenProxmark(1)) {
199 fprintf(stderr,"PROXMARK3: NOT FOUND!\n");
200 marg.usb_present = 0;
203 marg.usb_present = 1;
207 sp
= uart_open(argv
[1]);
208 if (sp
== INVALID_SERIAL_PORT
) {
209 printf("ERROR: invalid serial port\n");
210 marg
.usb_present
= 0;
213 marg
.usb_present
= 1;
217 // If the user passed the filename of the 'script' to execute, get it
218 if (argc
> 2 && argv
[2]) {
219 marg
.script_cmds_file
= argv
[2];
222 pthread_create(&main_loop_t
, NULL
, &main_loop
, &marg
);
223 InitGraphics(argc
, argv
);
227 pthread_join(main_loop_t
, NULL
);
229 // if (marg.usb_present == 1) {