]>
cvs.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 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)
141 uint32_t mem_left
= 0;
143 mem_left
= (mem_avail
* 1024) - mem_used
;
145 PrintAndLog("Nonvolatile Program Memory Size: %uK bytes. Used: %u bytes (%2.0f\%). Free: %u bytes (%2.0f\%).",
148 mem_avail
== 0 ? 0.0f
: (float)mem_used
/(mem_avail
*1024)*100,
150 mem_avail
== 0 ? 0.0f
: (float)mem_left
/(mem_avail
*1024)*100
152 switch((iChipID
&0xF000)>>12)
155 sprintf(asBuff
,"None");
158 sprintf(asBuff
,"8K bytes");
161 sprintf(asBuff
,"16K bytes");
164 sprintf(asBuff
,"32K bytes");
167 sprintf(asBuff
,"64K bytes");
170 sprintf(asBuff
,"128K bytes");
173 sprintf(asBuff
,"256K bytes");
176 sprintf(asBuff
,"512K bytes");
179 sprintf(asBuff
,"1024K bytes");
182 sprintf(asBuff
,"2048K bytes");
185 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
186 switch((iChipID
&0xF0000)>>16)
189 sprintf(asBuff
,"1K bytes");
192 sprintf(asBuff
,"2K bytes");
195 sprintf(asBuff
,"6K bytes");
198 sprintf(asBuff
,"112K bytes");
201 sprintf(asBuff
,"4K bytes");
204 sprintf(asBuff
,"80K bytes");
207 sprintf(asBuff
,"160K bytes");
210 sprintf(asBuff
,"8K bytes");
213 sprintf(asBuff
,"16K bytes");
216 sprintf(asBuff
,"32K bytes");
219 sprintf(asBuff
,"64K bytes");
222 sprintf(asBuff
,"128K bytes");
225 sprintf(asBuff
,"256K bytes");
228 sprintf(asBuff
,"96K bytes");
231 sprintf(asBuff
,"512K bytes");
234 PrintAndLog("Internal SRAM Size: %s",asBuff
);
235 switch((iChipID
&0xFF00000)>>20)
238 sprintf(asBuff
,"AT91SAM9xx Series");
241 sprintf(asBuff
,"AT91SAM9XExx Series");
244 sprintf(asBuff
,"AT91x34 Series");
247 sprintf(asBuff
,"CAP7 Series");
250 sprintf(asBuff
,"CAP9 Series");
253 sprintf(asBuff
,"CAP11 Series");
256 sprintf(asBuff
,"AT91x40 Series");
259 sprintf(asBuff
,"AT91x42 Series");
262 sprintf(asBuff
,"AT91x55 Series");
265 sprintf(asBuff
,"AT91SAM7Axx Series");
268 sprintf(asBuff
,"AT91SAM7AQxx Series");
271 sprintf(asBuff
,"AT91x63 Series");
274 sprintf(asBuff
,"AT91SAM7Sxx Series");
277 sprintf(asBuff
,"AT91SAM7XCxx Series");
280 sprintf(asBuff
,"AT91SAM7SExx Series");
283 sprintf(asBuff
,"AT91SAM7Lxx Series");
286 sprintf(asBuff
,"AT91SAM7Xxx Series");
289 sprintf(asBuff
,"AT91x92 Series");
292 sprintf(asBuff
,"AT75Cxx Series");
295 PrintAndLog("Architecture Identifier: %s",asBuff
);
296 switch((iChipID
&0x70000000)>>28)
299 sprintf(asBuff
,"ROM");
302 sprintf(asBuff
,"ROMless or on-chip Flash");
305 sprintf(asBuff
,"SRAM emulating ROM");
308 sprintf(asBuff
,"Embedded Flash Memory");
311 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
314 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
317 int CmdDetectReader(const char *Cmd
)
319 UsbCommand c
= {CMD_LISTEN_READER_FIELD
};
320 // 'l' means LF - 125/134 kHz
323 } else if (*Cmd
== 'h') {
325 } else if (*Cmd
!= '\0') {
326 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
329 clearCommandBuffer();
335 int CmdFPGAOff(const char *Cmd
)
337 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
338 clearCommandBuffer();
343 int CmdLCD(const char *Cmd
)
347 UsbCommand c
= {CMD_LCD
};
348 sscanf(Cmd
, "%x %d", &i
, &j
);
350 c
.arg
[0] = i
& 0x1ff;
351 clearCommandBuffer();
357 int CmdLCDReset(const char *Cmd
)
359 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
360 clearCommandBuffer();
365 int CmdReadmem(const char *Cmd
)
367 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
368 clearCommandBuffer();
373 int CmdReset(const char *Cmd
)
375 UsbCommand c
= {CMD_HARDWARE_RESET
};
376 clearCommandBuffer();
382 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
385 int CmdSetDivisor(const char *Cmd
)
387 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
389 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
390 PrintAndLog("divisor must be between 19 and 255");
394 clearCommandBuffer();
396 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
400 int CmdSetMux(const char *Cmd
)
402 UsbCommand c
= {CMD_SET_ADC_MUX
};
403 if (strcmp(Cmd
, "lopkd") == 0) c
.arg
[0] = 0;
404 else if (strcmp(Cmd
, "loraw") == 0) c
.arg
[0] = 1;
405 else if (strcmp(Cmd
, "hipkd") == 0) c
.arg
[0] = 2;
406 else if (strcmp(Cmd
, "hiraw") == 0) c
.arg
[0] = 3;
407 clearCommandBuffer();
412 int CmdTune(const char *Cmd
)
414 return CmdTuneSamples(Cmd
);
417 int CmdVersion(const char *Cmd
)
419 clearCommandBuffer();
420 UsbCommand c
= {CMD_VERSION
};
421 static UsbCommand resp
= {0, {0, 0, 0}};
423 if (resp
.arg
[0] == 0 && resp
.arg
[1] == 0) { // no cached information available
425 if (WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)) {
426 PrintAndLog("Prox/RFID mark3 RFID instrument");
427 PrintAndLog((char*)resp
.d
.asBytes
);
428 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
431 PrintAndLog("[[[ Cached information ]]]\n");
432 PrintAndLog("Prox/RFID mark3 RFID instrument");
433 PrintAndLog((char*)resp
.d
.asBytes
);
434 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
440 int CmdStatus(const char *Cmd
)
442 uint8_t speed_test_buffer
[USB_CMD_DATA_SIZE
];
443 sample_buf
= speed_test_buffer
;
444 clearCommandBuffer();
445 UsbCommand c
= {CMD_STATUS
};
447 if (!WaitForResponseTimeout(CMD_ACK
, &c
, 1900))
448 PrintAndLog("Status command failed. USB Speed Test timed out");
452 int CmdPing(const char *Cmd
)
454 clearCommandBuffer();
456 UsbCommand c
= {CMD_PING
};
458 if (WaitForResponseTimeout(CMD_ACK
, &resp
, 1000))
459 PrintAndLog("Ping successfull");
461 PrintAndLog("Ping failed");
465 static command_t CommandTable
[] =
467 {"help", CmdHelp
, 1, "This help"},
468 {"detectreader", CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
469 {"fpgaoff", CmdFPGAOff
, 0, "Set FPGA off"},
470 {"lcd", CmdLCD
, 0, "<HEX command> <count> -- Send command/data to LCD"},
471 {"lcdreset", CmdLCDReset
, 0, "Hardware reset LCD"},
472 {"readmem", CmdReadmem
, 0, "[address] -- Read memory at decimal address from flash"},
473 {"reset", CmdReset
, 0, "Reset the Proxmark3"},
474 {"setlfdivisor", CmdSetDivisor
, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
475 {"setmux", CmdSetMux
, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
476 {"tune", CmdTune
, 0, "Measure antenna tuning"},
477 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
478 {"status", CmdStatus
, 0, "Show runtime status information about the connected Proxmark"},
479 {"ping", CmdPing
, 0, "Test if the pm3 is responsive"},
480 {NULL
, NULL
, 0, NULL
}
483 int CmdHW(const char *Cmd
) {
484 clearCommandBuffer();
485 CmdsParse(CommandTable
, Cmd
);
489 int CmdHelp(const char *Cmd
)
491 CmdsHelp(CommandTable
);