]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
6549d6ea7c6572dbbb0a8d3e66e554eff5c5216f
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
16 #include "proxmark3.h"
17 #include "cmdparser.h"
23 /* low-level hardware control */
25 static int CmdHelp(const char *Cmd
);
27 static void lookupChipID(uint32_t iChipID
, uint32_t mem_used
)
30 memset(asBuff
, 0, sizeof(asBuff
));
31 uint32_t mem_avail
= 0;
36 sprintf(asBuff
,"AT91SAM7S512 Rev A");
39 sprintf(asBuff
,"AT91SAM7S512 Rev B");
42 sprintf(asBuff
,"AT91SAM7S256 Rev A");
45 sprintf(asBuff
,"AT91SAM7S256 Rev B");
48 sprintf(asBuff
,"AT91SAM7S256 Rev C");
51 sprintf(asBuff
,"AT91SAM7S256 Rev D");
54 sprintf(asBuff
,"AT91SAM7S128 Rev A");
57 sprintf(asBuff
,"AT91SAM7S128 Rev B");
60 sprintf(asBuff
,"AT91SAM7S128 Rev C");
63 sprintf(asBuff
,"AT91SAM7S128 Rev D");
66 sprintf(asBuff
,"AT91SAM7S64 Rev A");
69 sprintf(asBuff
,"AT91SAM7S64 Rev B");
72 sprintf(asBuff
,"AT91SAM7S64 Rev C");
75 sprintf(asBuff
,"AT91SAM7S321 Rev A");
78 sprintf(asBuff
,"AT91SAM7S32 Rev A");
81 sprintf(asBuff
,"AT91SAM7S32 Rev B");
84 sprintf(asBuff
,"AT9SAM7S161 Rev A");
87 sprintf(asBuff
,"AT91SAM7S16 Rev A");
90 PrintAndLog("uC: %s",asBuff
);
91 switch((iChipID
&0xE0)>>5)
94 sprintf(asBuff
,"ARM946ES");
97 sprintf(asBuff
,"ARM7TDMI");
100 sprintf(asBuff
,"ARM920T");
103 sprintf(asBuff
,"ARM926EJS");
106 PrintAndLog("Embedded Processor: %s",asBuff
);
107 switch((iChipID
&0xF00)>>8)
140 PrintAndLog("Nonvolatile Program Memory Size: %dK bytes. Used: %d bytes (%2.0f\%). Free: %d bytes (%2.0f\%).",
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
147 switch((iChipID
&0xF000)>>12)
150 sprintf(asBuff
,"None");
153 sprintf(asBuff
,"8K bytes");
156 sprintf(asBuff
,"16K bytes");
159 sprintf(asBuff
,"32K bytes");
162 sprintf(asBuff
,"64K bytes");
165 sprintf(asBuff
,"128K bytes");
168 sprintf(asBuff
,"256K bytes");
171 sprintf(asBuff
,"512K bytes");
174 sprintf(asBuff
,"1024K bytes");
177 sprintf(asBuff
,"2048K bytes");
180 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
181 switch((iChipID
&0xF0000)>>16)
184 sprintf(asBuff
,"1K bytes");
187 sprintf(asBuff
,"2K bytes");
190 sprintf(asBuff
,"6K bytes");
193 sprintf(asBuff
,"112K bytes");
196 sprintf(asBuff
,"4K bytes");
199 sprintf(asBuff
,"80K bytes");
202 sprintf(asBuff
,"160K bytes");
205 sprintf(asBuff
,"8K bytes");
208 sprintf(asBuff
,"16K bytes");
211 sprintf(asBuff
,"32K bytes");
214 sprintf(asBuff
,"64K bytes");
217 sprintf(asBuff
,"128K bytes");
220 sprintf(asBuff
,"256K bytes");
223 sprintf(asBuff
,"96K bytes");
226 sprintf(asBuff
,"512K bytes");
229 PrintAndLog("Internal SRAM Size: %s",asBuff
);
230 switch((iChipID
&0xFF00000)>>20)
233 sprintf(asBuff
,"AT91SAM9xx Series");
236 sprintf(asBuff
,"AT91SAM9XExx Series");
239 sprintf(asBuff
,"AT91x34 Series");
242 sprintf(asBuff
,"CAP7 Series");
245 sprintf(asBuff
,"CAP9 Series");
248 sprintf(asBuff
,"CAP11 Series");
251 sprintf(asBuff
,"AT91x40 Series");
254 sprintf(asBuff
,"AT91x42 Series");
257 sprintf(asBuff
,"AT91x55 Series");
260 sprintf(asBuff
,"AT91SAM7Axx Series");
263 sprintf(asBuff
,"AT91SAM7AQxx Series");
266 sprintf(asBuff
,"AT91x63 Series");
269 sprintf(asBuff
,"AT91SAM7Sxx Series");
272 sprintf(asBuff
,"AT91SAM7XCxx Series");
275 sprintf(asBuff
,"AT91SAM7SExx Series");
278 sprintf(asBuff
,"AT91SAM7Lxx Series");
281 sprintf(asBuff
,"AT91SAM7Xxx Series");
284 sprintf(asBuff
,"AT91x92 Series");
287 sprintf(asBuff
,"AT75Cxx Series");
290 PrintAndLog("Architecture Identifier: %s",asBuff
);
291 switch((iChipID
&0x70000000)>>28)
294 sprintf(asBuff
,"ROM");
297 sprintf(asBuff
,"ROMless or on-chip Flash");
300 sprintf(asBuff
,"SRAM emulating ROM");
303 sprintf(asBuff
,"Embedded Flash Memory");
306 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
309 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
312 int CmdDetectReader(const char *Cmd
)
314 UsbCommand c
= {CMD_LISTEN_READER_FIELD
};
315 // 'l' means LF - 125/134 kHz
318 } else if (*Cmd
== 'h') {
320 } else if (*Cmd
!= '\0') {
321 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
324 clearCommandBuffer();
330 int CmdFPGAOff(const char *Cmd
)
332 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
333 clearCommandBuffer();
338 int CmdLCD(const char *Cmd
)
342 UsbCommand c
= {CMD_LCD
};
343 sscanf(Cmd
, "%x %d", &i
, &j
);
345 c
.arg
[0] = i
& 0x1ff;
346 clearCommandBuffer();
352 int CmdLCDReset(const char *Cmd
)
354 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
355 clearCommandBuffer();
360 int CmdReadmem(const char *Cmd
)
362 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
363 clearCommandBuffer();
368 int CmdReset(const char *Cmd
)
370 UsbCommand c
= {CMD_HARDWARE_RESET
};
371 clearCommandBuffer();
377 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
380 int CmdSetDivisor(const char *Cmd
)
382 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
384 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
385 PrintAndLog("divisor must be between 19 and 255");
389 clearCommandBuffer();
391 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
395 int CmdSetMux(const char *Cmd
)
397 UsbCommand c
= {CMD_SET_ADC_MUX
};
398 if (strcmp(Cmd
, "lopkd") == 0) c
.arg
[0] = 0;
399 else if (strcmp(Cmd
, "loraw") == 0) c
.arg
[0] = 1;
400 else if (strcmp(Cmd
, "hipkd") == 0) c
.arg
[0] = 2;
401 else if (strcmp(Cmd
, "hiraw") == 0) c
.arg
[0] = 3;
402 clearCommandBuffer();
407 int CmdTune(const char *Cmd
)
409 return CmdTuneSamples(Cmd
);
412 int CmdVersion(const char *Cmd
)
414 clearCommandBuffer();
415 UsbCommand c
= {CMD_VERSION
};
416 static UsbCommand resp
= {0, {0, 0, 0}};
418 if (resp
.arg
[0] == 0 && resp
.arg
[1] == 0) { // no cached information available
420 if (WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)) {
421 PrintAndLog("Prox/RFID mark3 RFID instrument");
422 PrintAndLog((char*)resp
.d
.asBytes
);
423 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
426 PrintAndLog("[[[ Cached information ]]]\n");
427 PrintAndLog("Prox/RFID mark3 RFID instrument");
428 PrintAndLog((char*)resp
.d
.asBytes
);
429 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
435 int CmdStatus(const char *Cmd
)
437 uint8_t speed_test_buffer
[USB_CMD_DATA_SIZE
];
438 sample_buf
= speed_test_buffer
;
439 clearCommandBuffer();
440 UsbCommand c
= {CMD_STATUS
};
442 if (!WaitForResponseTimeout(CMD_ACK
, &c
, 1900))
443 PrintAndLog("Status command failed. USB Speed Test timed out");
447 int CmdPing(const char *Cmd
)
449 clearCommandBuffer();
451 UsbCommand c
= {CMD_PING
};
453 if (WaitForResponseTimeout(CMD_ACK
, &resp
, 1000))
454 PrintAndLog("Ping successfull");
456 PrintAndLog("Ping failed");
460 static command_t CommandTable
[] =
462 {"help", CmdHelp
, 1, "This help"},
463 {"detectreader", CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
464 {"fpgaoff", CmdFPGAOff
, 0, "Set FPGA off"},
465 {"lcd", CmdLCD
, 0, "<HEX command> <count> -- Send command/data to LCD"},
466 {"lcdreset", CmdLCDReset
, 0, "Hardware reset LCD"},
467 {"readmem", CmdReadmem
, 0, "[address] -- Read memory at decimal address from flash"},
468 {"reset", CmdReset
, 0, "Reset the Proxmark3"},
469 {"setlfdivisor", CmdSetDivisor
, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
470 {"setmux", CmdSetMux
, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
471 {"tune", CmdTune
, 0, "Measure antenna tuning"},
472 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
473 {"status", CmdStatus
, 0, "Show runtime status information about the connected Proxmark"},
474 {"ping", CmdPing
, 0, "Test if the pm3 is responsive"},
475 {NULL
, NULL
, 0, NULL
}
478 int CmdHW(const char *Cmd
) {
479 clearCommandBuffer();
480 CmdsParse(CommandTable
, Cmd
);
484 int CmdHelp(const char *Cmd
)
486 CmdsHelp(CommandTable
);