]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdmain.c
Attempt at getting the windows client to at least compile without bombing out with...
[proxmark3-svn] / client / cmdmain.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5 #ifdef WIN32
6 #include <windows.h>
7 #endif
8 #include "cmdparser.h"
9 #include "data.h"
10 #include "usb_cmd.h"
11 #include "ui.h"
12 #include "cmdhf.h"
13 #include "cmddata.h"
14 #include "cmdhw.h"
15 #include "cmdlf.h"
16 #include "cmdmain.h"
17 #include "proxusb.h"
18
19 unsigned int current_command = CMD_UNKNOWN;
20 unsigned int received_command = CMD_UNKNOWN;
21
22 static int CmdHelp(const char *Cmd);
23 static int CmdQuit(const char *Cmd);
24
25 static command_t CommandTable[] =
26 {
27 {"help", CmdHelp, 1, "This help. Use '<command> help' for details of the following commands:\n"},
28 {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"},
29 {"exit", CmdQuit, 1, "Exit program"},
30 {"hf", CmdHF, 1, "{ HF commands... }"},
31 {"hw", CmdHW, 1, "{ Hardware commands... }"},
32 {"lf", CmdLF, 1, "{ LF commands... }"},
33 {"quit", CmdQuit, 1, "Quit program"},
34 {NULL, NULL, 0, NULL}
35 };
36
37 int CmdHelp(const char *Cmd)
38 {
39 CmdsHelp(CommandTable);
40 return 0;
41 }
42
43 int CmdQuit(const char *Cmd)
44 {
45 exit(0);
46 return 0;
47 }
48
49 void WaitForResponse(uint32_t response_type)
50 {
51 while (received_command != response_type) {
52 #ifdef WIN32
53 UsbCommand c;
54 if (ReceiveCommandPoll(&c))
55 UsbCommandReceived(&c);
56 Sleep(0);
57 #else
58 usleep(10000); // XXX ugh
59 #endif
60 }
61 received_command = CMD_UNKNOWN;
62 }
63
64 //-----------------------------------------------------------------------------
65 // Entry point into our code: called whenever the user types a command and
66 // then presses Enter, which the full command line that they typed.
67 //-----------------------------------------------------------------------------
68 void CommandReceived(char *Cmd)
69 {
70 CmdsParse(CommandTable, Cmd);
71 }
72
73 //-----------------------------------------------------------------------------
74 // Entry point into our code: called whenever we received a packet over USB
75 // that we weren't necessarily expecting, for example a debug print.
76 //-----------------------------------------------------------------------------
77 void UsbCommandReceived(UsbCommand *UC)
78 {
79 // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command);
80 /* If we recognize a response, return to avoid further processing */
81 switch(UC->cmd) {
82 case CMD_DEBUG_PRINT_STRING: {
83 char s[100];
84 if(UC->arg[0] > 70 || UC->arg[0] < 0) {
85 UC->arg[0] = 0;
86 }
87 memcpy(s, UC->d.asBytes, UC->arg[0]);
88 s[UC->arg[0]] = '\0';
89 PrintAndLog("#db# %s", s);
90 return;
91 }
92
93 case CMD_DEBUG_PRINT_INTEGERS:
94 PrintAndLog("#db# %08x, %08x, %08x\r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
95 return;
96
97 case CMD_MEASURED_ANTENNA_TUNING: {
98 int peakv, peakf;
99 int vLf125, vLf134, vHf;
100 vLf125 = UC->arg[0] & 0xffff;
101 vLf134 = UC->arg[0] >> 16;
102 vHf = UC->arg[1] & 0xffff;;
103 peakf = UC->arg[2] & 0xffff;
104 peakv = UC->arg[2] >> 16;
105 PrintAndLog("");
106 PrintAndLog("");
107 PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);
108 PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0);
109 PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
110 PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
111 if (peakv<2000)
112 PrintAndLog("# Your LF antenna is unusable.");
113 else if (peakv<10000)
114 PrintAndLog("# Your LF antenna is marginal.");
115 if (vHf<2000)
116 PrintAndLog("# Your HF antenna is unusable.");
117 else if (vHf<5000)
118 PrintAndLog("# Your HF antenna is marginal.");
119 return;
120 }
121 default:
122 break;
123 }
124 /* Maybe it's a response: */
125 switch(current_command) {
126 case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
127 if (UC->cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) goto unexpected_response;
128 int i;
129 for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i];
130 received_command = UC->cmd;
131 return;
132 case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
133 case CMD_DOWNLOADED_SIM_SAMPLES_125K:
134 if (UC->cmd != CMD_ACK) goto unexpected_response;
135 // got ACK
136 received_command = UC->cmd;
137 return;
138 default:
139 unexpected_response:
140 PrintAndLog("unrecognized command %08x\n", UC->cmd);
141 break;
142 }
143 }
Impressum, Datenschutz