Merge pull request #107 from p-l-/fix-hfmf
[legacy-proxmark3.git] / client / cli.c
blobc5c2acf46dbea4b0cef7b0188f2eb85077f3d520
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
4 // the license.
5 //-----------------------------------------------------------------------------
6 // Command line binary
7 //-----------------------------------------------------------------------------
9 #include <stdio.h>
10 #include "sleep.h"
11 #include "ui.h"
12 #include "proxusb.h"
13 #include "cmdmain.h"
15 #define HANDLE_ERROR if (error_occured) { \
16 error_occured = 0;\
17 break;\
20 int main(int argc, char **argv)
22 if (argc != 3 && argc != 4)
24 printf("\n\tusage: cli <command 1> <command 2> [logfile (default cli.log)]\n");
25 printf("\n");
26 printf("\texample: cli hi14asnoop hi14alist h14a.log\n");
27 printf("\n");
28 return -1;
31 usb_init();
32 if (argc == 4)
33 SetLogFilename(argv[3]);
34 else
35 SetLogFilename("cli.log");
37 return_on_error = 1;
39 while (1) {
40 while (!OpenProxmark(0)) { sleep(1); }
41 while (1) {
42 UsbCommand cmdbuf;
43 CommandReceived(argv[1]);
44 HANDLE_ERROR;
45 ReceiveCommand(&cmdbuf);
46 HANDLE_ERROR;
47 for (int i = 0; i < 5; ++i) {
48 ReceiveCommandPoll(&cmdbuf);
50 HANDLE_ERROR;
51 CommandReceived(argv[2]);
52 HANDLE_ERROR;
56 CloseProxmark();
57 return 0;