]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdmain.c
Added block command for T55xx and support for cloning HID long format
[proxmark3-svn] / client / cmdmain.c
CommitLineData
a553f267 1//-----------------------------------------------------------------------------
2// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3//
4// This code is licensed to you under the terms of the GNU GPL, version 2 or,
5// at your option, any later version. See the LICENSE.txt file for the text of
6// the license.
7//-----------------------------------------------------------------------------
8// Main command parser entry point
9//-----------------------------------------------------------------------------
10
7fe9b0b7 11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <string.h>
91c38cf7 15#include "sleep.h"
7fe9b0b7 16#include "cmdparser.h"
17#include "data.h"
18#include "usb_cmd.h"
19#include "ui.h"
20#include "cmdhf.h"
21#include "cmddata.h"
22#include "cmdhw.h"
23#include "cmdlf.h"
24#include "cmdmain.h"
25
26unsigned int current_command = CMD_UNKNOWN;
27unsigned int received_command = CMD_UNKNOWN;
534983d7 28UsbCommand current_response;
50193c1e 29UsbCommand current_response_user;
7fe9b0b7 30
31static int CmdHelp(const char *Cmd);
32static int CmdQuit(const char *Cmd);
33
34static command_t CommandTable[] =
35{
c37d2e70 36 {"help", CmdHelp, 1, "This help. Use '<command> help' for details of the following commands:\n"},
37239a7c 37 {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"},
7fe9b0b7 38 {"exit", CmdQuit, 1, "Exit program"},
37239a7c 39 {"hf", CmdHF, 1, "{ HF commands... }"},
40 {"hw", CmdHW, 1, "{ Hardware commands... }"},
41 {"lf", CmdLF, 1, "{ LF commands... }"},
7fe9b0b7 42 {"quit", CmdQuit, 1, "Quit program"},
43 {NULL, NULL, 0, NULL}
44};
45
46int CmdHelp(const char *Cmd)
47{
48 CmdsHelp(CommandTable);
49 return 0;
50}
51
52int CmdQuit(const char *Cmd)
53{
54 exit(0);
55 return 0;
56}
57
534983d7 58UsbCommand * WaitForResponseTimeout(uint32_t response_type, uint32_t ms_timeout) {
50193c1e 59 UsbCommand * ret = NULL;
534983d7 60 int i=0;
61
62 for(i=0; received_command != response_type && i < ms_timeout / 10; i++) {
63 msleep(10); // XXX ugh
64 }
50193c1e 65
f397b5cc 66 // There was an evil BUG
50193c1e
M
67 memcpy(&current_response_user, &current_response, sizeof(UsbCommand));
68 ret = &current_response_user;
534983d7 69
70 if(received_command != response_type)
71 ret = NULL;
72
73 received_command = CMD_UNKNOWN;
74
75 return ret;
76}
77
78UsbCommand * WaitForResponse(uint32_t response_type)
7fe9b0b7 79{
534983d7 80 return WaitForResponseTimeout(response_type, -1);
7fe9b0b7 81}
82
83//-----------------------------------------------------------------------------
84// Entry point into our code: called whenever the user types a command and
85// then presses Enter, which the full command line that they typed.
86//-----------------------------------------------------------------------------
87void CommandReceived(char *Cmd)
88{
89 CmdsParse(CommandTable, Cmd);
90}
91
92//-----------------------------------------------------------------------------
93// Entry point into our code: called whenever we received a packet over USB
94// that we weren't necessarily expecting, for example a debug print.
95//-----------------------------------------------------------------------------
96void UsbCommandReceived(UsbCommand *UC)
97{
98 // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command);
99 /* If we recognize a response, return to avoid further processing */
100 switch(UC->cmd) {
db09cb3a 101 // First check if we are handling a debug message
7fe9b0b7 102 case CMD_DEBUG_PRINT_STRING: {
103 char s[100];
104 if(UC->arg[0] > 70 || UC->arg[0] < 0) {
105 UC->arg[0] = 0;
106 }
107 memcpy(s, UC->d.asBytes, UC->arg[0]);
108 s[UC->arg[0]] = '\0';
ab8b654e 109 PrintAndLog("#db# %s ", s);
7fe9b0b7 110 return;
db09cb3a 111 } break;
7fe9b0b7 112
db09cb3a 113 case CMD_DEBUG_PRINT_INTEGERS: {
ab8b654e 114 PrintAndLog("#db# %08x, %08x, %08x \r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
7fe9b0b7 115 return;
db09cb3a 116 } break;
7fe9b0b7 117
118 case CMD_MEASURED_ANTENNA_TUNING: {
119 int peakv, peakf;
120 int vLf125, vLf134, vHf;
121 vLf125 = UC->arg[0] & 0xffff;
122 vLf134 = UC->arg[0] >> 16;
123 vHf = UC->arg[1] & 0xffff;;
124 peakf = UC->arg[2] & 0xffff;
125 peakv = UC->arg[2] >> 16;
126 PrintAndLog("");
7fe9b0b7 127 PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);
128 PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0);
129 PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
130 PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
131 if (peakv<2000)
132 PrintAndLog("# Your LF antenna is unusable.");
133 else if (peakv<10000)
134 PrintAndLog("# Your LF antenna is marginal.");
135 if (vHf<2000)
136 PrintAndLog("# Your HF antenna is unusable.");
137 else if (vHf<5000)
138 PrintAndLog("# Your HF antenna is marginal.");
db09cb3a 139 } break;
140
141 default: {
142 // Maybe it's a response
143 switch(current_command) {
144 case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K: {
145 if (UC->cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) {
146 PrintAndLog("unrecognized command %08x\n", UC->cmd);
147 break;
148 }
149 int i;
150 for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i];
151 received_command = UC->cmd;
152 } break;
153
154 default: {
155 } break;
156 }
157 // Store the last received command
158 received_command = UC->cmd;
159 memcpy(&current_response, UC, sizeof(UsbCommand));
160 } break;
7fe9b0b7 161 }
db09cb3a 162 received_command = UC->cmd;
163/*
164 // Maybe it's a response:
7fe9b0b7 165 switch(current_command) {
166 case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
167 if (UC->cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) goto unexpected_response;
168 int i;
169 for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i];
170 received_command = UC->cmd;
171 return;
bdd1de1b 172 case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
7fe9b0b7 173 case CMD_DOWNLOADED_SIM_SAMPLES_125K:
174 if (UC->cmd != CMD_ACK) goto unexpected_response;
175 // got ACK
176 received_command = UC->cmd;
177 return;
178 default:
179 unexpected_response:
534983d7 180
181 if(UC->cmd != CMD_ACK)
ab8b654e 182 PrintAndLog("unrecognized command %08x \n", UC->cmd);
534983d7 183 else
184 memcpy(&current_response, UC, sizeof(UsbCommand));
185 received_command = UC->cmd;
7fe9b0b7 186 }
db09cb3a 187 */
c37d2e70 188}
Impressum, Datenschutz