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"
21 /* low-level hardware control */
23 static int CmdHelp(const char *Cmd
);
25 static void lookupChipID(uint32_t iChipID
)
31 sprintf(asBuff
,"AT91SAM7S512 Rev A");
34 sprintf(asBuff
,"AT91SAM7S512 Rev B");
37 sprintf(asBuff
,"AT91SAM7S256 Rev A");
40 sprintf(asBuff
,"AT91SAM7S256 Rev B");
43 sprintf(asBuff
,"AT91SAM7S256 Rev C");
46 sprintf(asBuff
,"AT91SAM7S256 Rev D");
49 sprintf(asBuff
,"AT91SAM7S128 Rev A");
52 sprintf(asBuff
,"AT91SAM7S128 Rev B");
55 sprintf(asBuff
,"AT91SAM7S128 Rev C");
58 sprintf(asBuff
,"AT91SAM7S128 Rev D");
61 sprintf(asBuff
,"AT91SAM7S64 Rev A");
64 sprintf(asBuff
,"AT91SAM7S64 Rev B");
67 sprintf(asBuff
,"AT91SAM7S64 Rev C");
70 sprintf(asBuff
,"AT91SAM7S321 Rev A");
73 sprintf(asBuff
,"AT91SAM7S32 Rev A");
76 sprintf(asBuff
,"AT91SAM7S32 Rev B");
79 sprintf(asBuff
,"AT9SAM7S161 Rev A");
82 sprintf(asBuff
,"AT91SAM7S16 Rev A");
85 PrintAndLog("uC: %s",asBuff
);
86 switch((iChipID
&0xE0)>>5)
89 sprintf(asBuff
,"ARM946ES");
92 sprintf(asBuff
,"ARM7TDMI");
95 sprintf(asBuff
,"ARM920T");
98 sprintf(asBuff
,"ARM926EJS");
101 PrintAndLog("Embedded Processor: %s",asBuff
);
102 switch((iChipID
&0xF00)>>8)
105 sprintf(asBuff
,"None");
108 sprintf(asBuff
,"8K bytes");
111 sprintf(asBuff
,"16K bytes");
114 sprintf(asBuff
,"32K bytes");
117 sprintf(asBuff
,"64K bytes");
120 sprintf(asBuff
,"128K bytes");
123 sprintf(asBuff
,"256K bytes");
126 sprintf(asBuff
,"512K bytes");
129 sprintf(asBuff
,"1024K bytes");
132 sprintf(asBuff
,"2048K bytes");
135 PrintAndLog("Nonvolatile Program Memory Size: %s",asBuff
);
136 switch((iChipID
&0xF000)>>12)
139 sprintf(asBuff
,"None");
142 sprintf(asBuff
,"8K bytes");
145 sprintf(asBuff
,"16K bytes");
148 sprintf(asBuff
,"32K bytes");
151 sprintf(asBuff
,"64K bytes");
154 sprintf(asBuff
,"128K bytes");
157 sprintf(asBuff
,"256K bytes");
160 sprintf(asBuff
,"512K bytes");
163 sprintf(asBuff
,"1024K bytes");
166 sprintf(asBuff
,"2048K bytes");
169 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
170 switch((iChipID
&0xF0000)>>16)
173 sprintf(asBuff
,"1K bytes");
176 sprintf(asBuff
,"2K bytes");
179 sprintf(asBuff
,"6K bytes");
182 sprintf(asBuff
,"112K bytes");
185 sprintf(asBuff
,"4K bytes");
188 sprintf(asBuff
,"80K bytes");
191 sprintf(asBuff
,"160K bytes");
194 sprintf(asBuff
,"8K bytes");
197 sprintf(asBuff
,"16K bytes");
200 sprintf(asBuff
,"32K bytes");
203 sprintf(asBuff
,"64K bytes");
206 sprintf(asBuff
,"128K bytes");
209 sprintf(asBuff
,"256K bytes");
212 sprintf(asBuff
,"96K bytes");
215 sprintf(asBuff
,"512K bytes");
218 PrintAndLog("Internal SRAM Size: %s",asBuff
);
219 switch((iChipID
&0xFF00000)>>20)
222 sprintf(asBuff
,"AT91SAM9xx Series");
225 sprintf(asBuff
,"AT91SAM9XExx Series");
228 sprintf(asBuff
,"AT91x34 Series");
231 sprintf(asBuff
,"CAP7 Series");
234 sprintf(asBuff
,"CAP9 Series");
237 sprintf(asBuff
,"CAP11 Series");
240 sprintf(asBuff
,"AT91x40 Series");
243 sprintf(asBuff
,"AT91x42 Series");
246 sprintf(asBuff
,"AT91x55 Series");
249 sprintf(asBuff
,"AT91SAM7Axx Series");
252 sprintf(asBuff
,"AT91SAM7AQxx Series");
255 sprintf(asBuff
,"AT91x63 Series");
258 sprintf(asBuff
,"AT91SAM7Sxx Series");
261 sprintf(asBuff
,"AT91SAM7XCxx Series");
264 sprintf(asBuff
,"AT91SAM7SExx Series");
267 sprintf(asBuff
,"AT91SAM7Lxx Series");
270 sprintf(asBuff
,"AT91SAM7Xxx Series");
273 sprintf(asBuff
,"AT91x92 Series");
276 sprintf(asBuff
,"AT75Cxx Series");
279 PrintAndLog("Architecture Identifier: %s",asBuff
);
280 switch((iChipID
&0x70000000)>>28)
283 sprintf(asBuff
,"ROM");
286 sprintf(asBuff
,"ROMless or on-chip Flash");
289 sprintf(asBuff
,"SRAM emulating ROM");
292 sprintf(asBuff
,"Embedded Flash Memory");
295 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
298 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
301 int CmdDetectReader(const char *Cmd
)
303 UsbCommand c
={CMD_LISTEN_READER_FIELD
};
304 // 'l' means LF - 125/134 kHz
307 } else if (*Cmd
== 'h') {
309 } else if (*Cmd
!= '\0') {
310 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
318 int CmdFPGAOff(const char *Cmd
)
320 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
325 int CmdLCD(const char *Cmd
)
329 UsbCommand c
={CMD_LCD
};
330 sscanf(Cmd
, "%x %d", &i
, &j
);
332 c
.arg
[0] = i
& 0x1ff;
338 int CmdLCDReset(const char *Cmd
)
340 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
345 int CmdReadmem(const char *Cmd
)
347 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
352 int CmdReset(const char *Cmd
)
354 UsbCommand c
= {CMD_HARDWARE_RESET
};
360 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
363 int CmdSetDivisor(const char *Cmd
)
365 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
366 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
367 PrintAndLog("divisor must be between 19 and 255");
370 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
375 int CmdSetMux(const char *Cmd
)
377 UsbCommand c
={CMD_SET_ADC_MUX
};
378 if (strcmp(Cmd
, "lopkd") == 0) {
380 } else if (strcmp(Cmd
, "loraw") == 0) {
382 } else if (strcmp(Cmd
, "hipkd") == 0) {
384 } else if (strcmp(Cmd
, "hiraw") == 0) {
391 int CmdTune(const char *Cmd
)
393 UsbCommand c
= {CMD_MEASURE_ANTENNA_TUNING
};
398 int CmdVersion(const char *Cmd
)
400 UsbCommand c
= {CMD_VERSION
};
403 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
404 lookupChipID(resp
.arg
[0]);
409 static command_t CommandTable
[] =
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"},
421 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
422 {NULL
, NULL
, 0, NULL
}
425 int CmdHW(const char *Cmd
)
427 CmdsParse(CommandTable
, Cmd
);
431 int CmdHelp(const char *Cmd
)
433 CmdsHelp(CommandTable
);