]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
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 uint32_t mem_avail
= 0;
35 sprintf(asBuff
,"AT91SAM7S512 Rev A");
38 sprintf(asBuff
,"AT91SAM7S512 Rev B");
41 sprintf(asBuff
,"AT91SAM7S256 Rev A");
44 sprintf(asBuff
,"AT91SAM7S256 Rev B");
47 sprintf(asBuff
,"AT91SAM7S256 Rev C");
50 sprintf(asBuff
,"AT91SAM7S256 Rev D");
53 sprintf(asBuff
,"AT91SAM7S128 Rev A");
56 sprintf(asBuff
,"AT91SAM7S128 Rev B");
59 sprintf(asBuff
,"AT91SAM7S128 Rev C");
62 sprintf(asBuff
,"AT91SAM7S128 Rev D");
65 sprintf(asBuff
,"AT91SAM7S64 Rev A");
68 sprintf(asBuff
,"AT91SAM7S64 Rev B");
71 sprintf(asBuff
,"AT91SAM7S64 Rev C");
74 sprintf(asBuff
,"AT91SAM7S321 Rev A");
77 sprintf(asBuff
,"AT91SAM7S32 Rev A");
80 sprintf(asBuff
,"AT91SAM7S32 Rev B");
83 sprintf(asBuff
,"AT9SAM7S161 Rev A");
86 sprintf(asBuff
,"AT91SAM7S16 Rev A");
89 PrintAndLog("uC: %s",asBuff
);
90 switch((iChipID
&0xE0)>>5)
93 sprintf(asBuff
,"ARM946ES");
96 sprintf(asBuff
,"ARM7TDMI");
99 sprintf(asBuff
,"ARM920T");
102 sprintf(asBuff
,"ARM926EJS");
105 PrintAndLog("Embedded Processor: %s",asBuff
);
106 switch((iChipID
&0xF00)>>8)
139 PrintAndLog("Nonvolatile Program Memory Size: %dK bytes. Used: %d bytes (%2.0f\%). Free: %d bytes (%2.0f\%).",
142 mem_avail
== 0 ? 0 : (float)mem_used
/(mem_avail
*1024)*100,
143 mem_avail
*1024 - mem_used
,
144 mem_avail
== 0 ? 0 : (float)(mem_avail
*1024-mem_used
)/(mem_avail
*1024)*100
146 switch((iChipID
&0xF000)>>12)
149 sprintf(asBuff
,"None");
152 sprintf(asBuff
,"8K bytes");
155 sprintf(asBuff
,"16K bytes");
158 sprintf(asBuff
,"32K bytes");
161 sprintf(asBuff
,"64K bytes");
164 sprintf(asBuff
,"128K bytes");
167 sprintf(asBuff
,"256K bytes");
170 sprintf(asBuff
,"512K bytes");
173 sprintf(asBuff
,"1024K bytes");
176 sprintf(asBuff
,"2048K bytes");
179 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
180 switch((iChipID
&0xF0000)>>16)
183 sprintf(asBuff
,"1K bytes");
186 sprintf(asBuff
,"2K bytes");
189 sprintf(asBuff
,"6K bytes");
192 sprintf(asBuff
,"112K bytes");
195 sprintf(asBuff
,"4K bytes");
198 sprintf(asBuff
,"80K bytes");
201 sprintf(asBuff
,"160K bytes");
204 sprintf(asBuff
,"8K bytes");
207 sprintf(asBuff
,"16K bytes");
210 sprintf(asBuff
,"32K bytes");
213 sprintf(asBuff
,"64K bytes");
216 sprintf(asBuff
,"128K bytes");
219 sprintf(asBuff
,"256K bytes");
222 sprintf(asBuff
,"96K bytes");
225 sprintf(asBuff
,"512K bytes");
228 PrintAndLog("Internal SRAM Size: %s",asBuff
);
229 switch((iChipID
&0xFF00000)>>20)
232 sprintf(asBuff
,"AT91SAM9xx Series");
235 sprintf(asBuff
,"AT91SAM9XExx Series");
238 sprintf(asBuff
,"AT91x34 Series");
241 sprintf(asBuff
,"CAP7 Series");
244 sprintf(asBuff
,"CAP9 Series");
247 sprintf(asBuff
,"CAP11 Series");
250 sprintf(asBuff
,"AT91x40 Series");
253 sprintf(asBuff
,"AT91x42 Series");
256 sprintf(asBuff
,"AT91x55 Series");
259 sprintf(asBuff
,"AT91SAM7Axx Series");
262 sprintf(asBuff
,"AT91SAM7AQxx Series");
265 sprintf(asBuff
,"AT91x63 Series");
268 sprintf(asBuff
,"AT91SAM7Sxx Series");
271 sprintf(asBuff
,"AT91SAM7XCxx Series");
274 sprintf(asBuff
,"AT91SAM7SExx Series");
277 sprintf(asBuff
,"AT91SAM7Lxx Series");
280 sprintf(asBuff
,"AT91SAM7Xxx Series");
283 sprintf(asBuff
,"AT91x92 Series");
286 sprintf(asBuff
,"AT75Cxx Series");
289 PrintAndLog("Architecture Identifier: %s",asBuff
);
290 switch((iChipID
&0x70000000)>>28)
293 sprintf(asBuff
,"ROM");
296 sprintf(asBuff
,"ROMless or on-chip Flash");
299 sprintf(asBuff
,"SRAM emulating ROM");
302 sprintf(asBuff
,"Embedded Flash Memory");
305 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
308 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
311 int CmdDetectReader(const char *Cmd
)
313 UsbCommand c
= {CMD_LISTEN_READER_FIELD
};
314 // 'l' means LF - 125/134 kHz
317 } else if (*Cmd
== 'h') {
319 } else if (*Cmd
!= '\0') {
320 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
323 clearCommandBuffer();
329 int CmdFPGAOff(const char *Cmd
)
331 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
332 clearCommandBuffer();
337 int CmdLCD(const char *Cmd
)
341 UsbCommand c
= {CMD_LCD
};
342 sscanf(Cmd
, "%x %d", &i
, &j
);
344 c
.arg
[0] = i
& 0x1ff;
345 clearCommandBuffer();
351 int CmdLCDReset(const char *Cmd
)
353 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
354 clearCommandBuffer();
359 int CmdReadmem(const char *Cmd
)
361 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
362 clearCommandBuffer();
367 int CmdReset(const char *Cmd
)
369 UsbCommand c
= {CMD_HARDWARE_RESET
};
370 clearCommandBuffer();
376 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
379 int CmdSetDivisor(const char *Cmd
)
381 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
383 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
384 PrintAndLog("divisor must be between 19 and 255");
388 clearCommandBuffer();
390 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
394 int CmdSetMux(const char *Cmd
)
396 UsbCommand c
= {CMD_SET_ADC_MUX
};
397 if (strcmp(Cmd
, "lopkd") == 0) c
.arg
[0] = 0;
398 else if (strcmp(Cmd
, "loraw") == 0) c
.arg
[0] = 1;
399 else if (strcmp(Cmd
, "hipkd") == 0) c
.arg
[0] = 2;
400 else if (strcmp(Cmd
, "hiraw") == 0) c
.arg
[0] = 3;
401 clearCommandBuffer();
406 int CmdTune(const char *Cmd
)
408 return CmdTuneSamples(Cmd
);
411 int CmdVersion(const char *Cmd
)
413 clearCommandBuffer();
414 UsbCommand c
= {CMD_VERSION
};
415 static UsbCommand resp
= {0, {0, 0, 0}};
417 if (resp
.arg
[0] == 0 && resp
.arg
[1] == 0) { // no cached information available
419 if (WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)) {
420 PrintAndLog("Prox/RFID mark3 RFID instrument");
421 PrintAndLog((char*)resp
.d
.asBytes
);
422 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
425 PrintAndLog("[[[ Cached information ]]]\n");
426 PrintAndLog("Prox/RFID mark3 RFID instrument");
427 PrintAndLog((char*)resp
.d
.asBytes
);
428 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
434 int CmdStatus(const char *Cmd
)
436 uint8_t speed_test_buffer
[USB_CMD_DATA_SIZE
];
437 sample_buf
= speed_test_buffer
;
438 clearCommandBuffer();
439 UsbCommand c
= {CMD_STATUS
};
441 if (!WaitForResponseTimeout(CMD_ACK
, &c
, 1900))
442 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
);