]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdhw.c
FIX: arguments took too much.
[proxmark3-svn] / client / cmdhw.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// Hardware commands
9//-----------------------------------------------------------------------------
10
7fe9b0b7 11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <limits.h>
15#include "ui.h"
902cb3c0 16#include "proxmark3.h"
7fe9b0b7 17#include "cmdparser.h"
02306bac 18#include "cmddata.h"
7fe9b0b7 19#include "cmdhw.h"
4f269f63 20#include "cmdmain.h"
14edfd09 21#include "cmddata.h"
7fe9b0b7 22
23/* low-level hardware control */
24
25static int CmdHelp(const char *Cmd);
26
4f269f63 27static void lookupChipID(uint32_t iChipID)
28{
29 char asBuff[100];
30 switch(iChipID)
31 {
32 case 0x270B0A40:
33 sprintf(asBuff,"AT91SAM7S512 Rev A");
34 break;
35 case 0x270B0A4F:
36 sprintf(asBuff,"AT91SAM7S512 Rev B");
37 break;
38 case 0x270D0940:
39 sprintf(asBuff,"AT91SAM7S256 Rev A");
40 break;
41 case 0x270B0941:
42 sprintf(asBuff,"AT91SAM7S256 Rev B");
43 break;
44 case 0x270B0942:
45 sprintf(asBuff,"AT91SAM7S256 Rev C");
46 break;
47 case 0x270B0943:
48 sprintf(asBuff,"AT91SAM7S256 Rev D");
49 break;
50 case 0x270C0740:
51 sprintf(asBuff,"AT91SAM7S128 Rev A");
52 break;
53 case 0x270A0741:
54 sprintf(asBuff,"AT91SAM7S128 Rev B");
55 break;
56 case 0x270A0742:
57 sprintf(asBuff,"AT91SAM7S128 Rev C");
58 break;
59 case 0x270A0743:
60 sprintf(asBuff,"AT91SAM7S128 Rev D");
61 break;
62 case 0x27090540:
63 sprintf(asBuff,"AT91SAM7S64 Rev A");
64 break;
65 case 0x27090543:
66 sprintf(asBuff,"AT91SAM7S64 Rev B");
67 break;
68 case 0x27090544:
69 sprintf(asBuff,"AT91SAM7S64 Rev C");
70 break;
71 case 0x27080342:
72 sprintf(asBuff,"AT91SAM7S321 Rev A");
73 break;
74 case 0x27080340:
75 sprintf(asBuff,"AT91SAM7S32 Rev A");
76 break;
77 case 0x27080341:
78 sprintf(asBuff,"AT91SAM7S32 Rev B");
79 break;
80 case 0x27050241:
81 sprintf(asBuff,"AT9SAM7S161 Rev A");
82 break;
83 case 0x27050240:
84 sprintf(asBuff,"AT91SAM7S16 Rev A");
85 break;
86 }
87 PrintAndLog("uC: %s",asBuff);
88 switch((iChipID&0xE0)>>5)
89 {
90 case 1:
91 sprintf(asBuff,"ARM946ES");
92 break;
93 case 2:
94 sprintf(asBuff,"ARM7TDMI");
95 break;
96 case 4:
97 sprintf(asBuff,"ARM920T");
98 break;
99 case 5:
100 sprintf(asBuff,"ARM926EJS");
101 break;
102 }
103 PrintAndLog("Embedded Processor: %s",asBuff);
104 switch((iChipID&0xF00)>>8)
105 {
106 case 0:
107 sprintf(asBuff,"None");
108 break;
109 case 1:
110 sprintf(asBuff,"8K bytes");
111 break;
112 case 2:
113 sprintf(asBuff,"16K bytes");
114 break;
115 case 3:
116 sprintf(asBuff,"32K bytes");
117 break;
118 case 5:
119 sprintf(asBuff,"64K bytes");
120 break;
121 case 7:
122 sprintf(asBuff,"128K bytes");
123 break;
124 case 9:
125 sprintf(asBuff,"256K bytes");
126 break;
127 case 10:
128 sprintf(asBuff,"512K bytes");
129 break;
130 case 12:
131 sprintf(asBuff,"1024K bytes");
132 break;
133 case 14:
134 sprintf(asBuff,"2048K bytes");
135 break;
136 }
137 PrintAndLog("Nonvolatile Program Memory Size: %s",asBuff);
138 switch((iChipID&0xF000)>>12)
139 {
140 case 0:
141 sprintf(asBuff,"None");
142 break;
143 case 1:
144 sprintf(asBuff,"8K bytes");
145 break;
146 case 2:
147 sprintf(asBuff,"16K bytes");
148 break;
149 case 3:
150 sprintf(asBuff,"32K bytes");
151 break;
152 case 5:
153 sprintf(asBuff,"64K bytes");
154 break;
155 case 7:
156 sprintf(asBuff,"128K bytes");
157 break;
158 case 9:
159 sprintf(asBuff,"256K bytes");
160 break;
161 case 10:
162 sprintf(asBuff,"512K bytes");
163 break;
164 case 12:
165 sprintf(asBuff,"1024K bytes");
166 break;
167 case 14:
168 sprintf(asBuff,"2048K bytes");
169 break;
170 }
171 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff);
172 switch((iChipID&0xF0000)>>16)
173 {
174 case 1:
175 sprintf(asBuff,"1K bytes");
176 break;
177 case 2:
178 sprintf(asBuff,"2K bytes");
179 break;
180 case 3:
181 sprintf(asBuff,"6K bytes");
182 break;
183 case 4:
184 sprintf(asBuff,"112K bytes");
185 break;
186 case 5:
187 sprintf(asBuff,"4K bytes");
188 break;
189 case 6:
190 sprintf(asBuff,"80K bytes");
191 break;
192 case 7:
193 sprintf(asBuff,"160K bytes");
194 break;
195 case 8:
196 sprintf(asBuff,"8K bytes");
197 break;
198 case 9:
199 sprintf(asBuff,"16K bytes");
200 break;
201 case 10:
202 sprintf(asBuff,"32K bytes");
203 break;
204 case 11:
205 sprintf(asBuff,"64K bytes");
206 break;
207 case 12:
208 sprintf(asBuff,"128K bytes");
209 break;
210 case 13:
211 sprintf(asBuff,"256K bytes");
212 break;
213 case 14:
214 sprintf(asBuff,"96K bytes");
215 break;
216 case 15:
217 sprintf(asBuff,"512K bytes");
218 break;
219 }
220 PrintAndLog("Internal SRAM Size: %s",asBuff);
221 switch((iChipID&0xFF00000)>>20)
222 {
223 case 0x19:
224 sprintf(asBuff,"AT91SAM9xx Series");
225 break;
226 case 0x29:
227 sprintf(asBuff,"AT91SAM9XExx Series");
228 break;
229 case 0x34:
230 sprintf(asBuff,"AT91x34 Series");
231 break;
232 case 0x37:
233 sprintf(asBuff,"CAP7 Series");
234 break;
235 case 0x39:
236 sprintf(asBuff,"CAP9 Series");
237 break;
238 case 0x3B:
239 sprintf(asBuff,"CAP11 Series");
240 break;
241 case 0x40:
242 sprintf(asBuff,"AT91x40 Series");
243 break;
244 case 0x42:
245 sprintf(asBuff,"AT91x42 Series");
246 break;
247 case 0x55:
248 sprintf(asBuff,"AT91x55 Series");
249 break;
250 case 0x60:
251 sprintf(asBuff,"AT91SAM7Axx Series");
252 break;
253 case 0x61:
254 sprintf(asBuff,"AT91SAM7AQxx Series");
255 break;
256 case 0x63:
257 sprintf(asBuff,"AT91x63 Series");
258 break;
259 case 0x70:
260 sprintf(asBuff,"AT91SAM7Sxx Series");
261 break;
262 case 0x71:
263 sprintf(asBuff,"AT91SAM7XCxx Series");
264 break;
265 case 0x72:
266 sprintf(asBuff,"AT91SAM7SExx Series");
267 break;
268 case 0x73:
269 sprintf(asBuff,"AT91SAM7Lxx Series");
270 break;
271 case 0x75:
272 sprintf(asBuff,"AT91SAM7Xxx Series");
273 break;
274 case 0x92:
275 sprintf(asBuff,"AT91x92 Series");
276 break;
277 case 0xF0:
278 sprintf(asBuff,"AT75Cxx Series");
279 break;
280 }
281 PrintAndLog("Architecture Identifier: %s",asBuff);
282 switch((iChipID&0x70000000)>>28)
283 {
284 case 0:
285 sprintf(asBuff,"ROM");
286 break;
287 case 1:
288 sprintf(asBuff,"ROMless or on-chip Flash");
289 break;
290 case 4:
291 sprintf(asBuff,"SRAM emulating ROM");
292 break;
293 case 2:
294 sprintf(asBuff,"Embedded Flash Memory");
295 break;
296 case 3:
297 sprintf(asBuff,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
298 break;
299 }
300 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff);
301}
302
7fe9b0b7 303int CmdDetectReader(const char *Cmd)
304{
305 UsbCommand c={CMD_LISTEN_READER_FIELD};
306 // 'l' means LF - 125/134 kHz
307 if(*Cmd == 'l') {
308 c.arg[0] = 1;
309 } else if (*Cmd == 'h') {
310 c.arg[0] = 2;
311 } else if (*Cmd != '\0') {
312 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
313 return 0;
314 }
315 SendCommand(&c);
316 return 0;
317}
318
319// ## FPGA Control
320int CmdFPGAOff(const char *Cmd)
321{
322 UsbCommand c = {CMD_FPGA_MAJOR_MODE_OFF};
323 SendCommand(&c);
324 return 0;
325}
326
327int CmdLCD(const char *Cmd)
328{
329 int i, j;
330
331 UsbCommand c={CMD_LCD};
332 sscanf(Cmd, "%x %d", &i, &j);
333 while (j--) {
334 c.arg[0] = i & 0x1ff;
335 SendCommand(&c);
336 }
337 return 0;
338}
339
340int CmdLCDReset(const char *Cmd)
341{
342 UsbCommand c = {CMD_LCD_RESET, {strtol(Cmd, NULL, 0), 0, 0}};
343 SendCommand(&c);
344 return 0;
345}
346
347int CmdReadmem(const char *Cmd)
348{
349 UsbCommand c = {CMD_READ_MEM, {strtol(Cmd, NULL, 0), 0, 0}};
350 SendCommand(&c);
351 return 0;
352}
353
354int CmdReset(const char *Cmd)
355{
356 UsbCommand c = {CMD_HARDWARE_RESET};
357 SendCommand(&c);
358 return 0;
359}
360
361/*
362 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
363 * 600kHz.
364 */
365int CmdSetDivisor(const char *Cmd)
366{
367 UsbCommand c = {CMD_SET_LF_DIVISOR, {strtol(Cmd, NULL, 0), 0, 0}};
7bb9d33e 368 if (c.arg[0] < 19 || c.arg[0] > 255) {
7fe9b0b7 369 PrintAndLog("divisor must be between 19 and 255");
370 } else {
371 SendCommand(&c);
372 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c.arg[0]+1));
373 }
374 return 0;
375}
376
377int CmdSetMux(const char *Cmd)
378{
379 UsbCommand c={CMD_SET_ADC_MUX};
380 if (strcmp(Cmd, "lopkd") == 0) {
381 c.arg[0] = 0;
382 } else if (strcmp(Cmd, "loraw") == 0) {
383 c.arg[0] = 1;
384 } else if (strcmp(Cmd, "hipkd") == 0) {
385 c.arg[0] = 2;
386 } else if (strcmp(Cmd, "hiraw") == 0) {
387 c.arg[0] = 3;
388 }
389 SendCommand(&c);
390 return 0;
391}
392
393int CmdTune(const char *Cmd)
394{
d3499d36 395 return CmdTuneSamples(Cmd);
7fe9b0b7 396}
397
398int CmdVersion(const char *Cmd)
399{
400 UsbCommand c = {CMD_VERSION};
4f269f63 401 UsbCommand resp;
7fe9b0b7 402 SendCommand(&c);
4f269f63 403 if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
404 lookupChipID(resp.arg[0]);
405 }
7fe9b0b7 406 return 0;
407}
408
409static command_t CommandTable[] =
410{
411 {"help", CmdHelp, 1, "This help"},
412 {"detectreader", CmdDetectReader,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
413 {"fpgaoff", CmdFPGAOff, 0, "Set FPGA off"},
414 {"lcd", CmdLCD, 0, "<HEX command> <count> -- Send command/data to LCD"},
415 {"lcdreset", CmdLCDReset, 0, "Hardware reset LCD"},
416 {"readmem", CmdReadmem, 0, "[address] -- Read memory at decimal address from flash"},
417 {"reset", CmdReset, 0, "Reset the Proxmark3"},
418 {"setlfdivisor", CmdSetDivisor, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
419 {"setmux", CmdSetMux, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
420 {"tune", CmdTune, 0, "Measure antenna tuning"},
72e930ef 421 {"version", CmdVersion, 0, "Show version information about the connected Proxmark"},
7fe9b0b7 422 {NULL, NULL, 0, NULL}
423};
424
425int CmdHW(const char *Cmd)
426{
427 CmdsParse(CommandTable, Cmd);
428 return 0;
429}
430
431int CmdHelp(const char *Cmd)
432{
433 CmdsHelp(CommandTable);
434 return 0;
435}
Impressum, Datenschutz