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