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"
22 /* low-level hardware control */
24 static int CmdHelp(const char *Cmd
);
26 static void lookupChipID(uint32_t iChipID
)
32 sprintf(asBuff
,"AT91SAM7S512 Rev A");
35 sprintf(asBuff
,"AT91SAM7S512 Rev B");
38 sprintf(asBuff
,"AT91SAM7S256 Rev A");
41 sprintf(asBuff
,"AT91SAM7S256 Rev B");
44 sprintf(asBuff
,"AT91SAM7S256 Rev C");
47 sprintf(asBuff
,"AT91SAM7S256 Rev D");
50 sprintf(asBuff
,"AT91SAM7S128 Rev A");
53 sprintf(asBuff
,"AT91SAM7S128 Rev B");
56 sprintf(asBuff
,"AT91SAM7S128 Rev C");
59 sprintf(asBuff
,"AT91SAM7S128 Rev D");
62 sprintf(asBuff
,"AT91SAM7S64 Rev A");
65 sprintf(asBuff
,"AT91SAM7S64 Rev B");
68 sprintf(asBuff
,"AT91SAM7S64 Rev C");
71 sprintf(asBuff
,"AT91SAM7S321 Rev A");
74 sprintf(asBuff
,"AT91SAM7S32 Rev A");
77 sprintf(asBuff
,"AT91SAM7S32 Rev B");
80 sprintf(asBuff
,"AT9SAM7S161 Rev A");
83 sprintf(asBuff
,"AT91SAM7S16 Rev A");
86 PrintAndLog("uC: %s",asBuff
);
87 switch((iChipID
&0xE0)>>5)
90 sprintf(asBuff
,"ARM946ES");
93 sprintf(asBuff
,"ARM7TDMI");
96 sprintf(asBuff
,"ARM920T");
99 sprintf(asBuff
,"ARM926EJS");
102 PrintAndLog("Embedded Processor: %s",asBuff
);
103 switch((iChipID
&0xF00)>>8)
106 sprintf(asBuff
,"None");
109 sprintf(asBuff
,"8K bytes");
112 sprintf(asBuff
,"16K bytes");
115 sprintf(asBuff
,"32K bytes");
118 sprintf(asBuff
,"64K bytes");
121 sprintf(asBuff
,"128K bytes");
124 sprintf(asBuff
,"256K bytes");
127 sprintf(asBuff
,"512K bytes");
130 sprintf(asBuff
,"1024K bytes");
133 sprintf(asBuff
,"2048K bytes");
136 PrintAndLog("Nonvolatile Program Memory Size: %s",asBuff
);
137 switch((iChipID
&0xF000)>>12)
140 sprintf(asBuff
,"None");
143 sprintf(asBuff
,"8K bytes");
146 sprintf(asBuff
,"16K bytes");
149 sprintf(asBuff
,"32K bytes");
152 sprintf(asBuff
,"64K bytes");
155 sprintf(asBuff
,"128K bytes");
158 sprintf(asBuff
,"256K bytes");
161 sprintf(asBuff
,"512K bytes");
164 sprintf(asBuff
,"1024K bytes");
167 sprintf(asBuff
,"2048K bytes");
170 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
171 switch((iChipID
&0xF0000)>>16)
174 sprintf(asBuff
,"1K bytes");
177 sprintf(asBuff
,"2K bytes");
180 sprintf(asBuff
,"6K bytes");
183 sprintf(asBuff
,"112K bytes");
186 sprintf(asBuff
,"4K bytes");
189 sprintf(asBuff
,"80K bytes");
192 sprintf(asBuff
,"160K bytes");
195 sprintf(asBuff
,"8K bytes");
198 sprintf(asBuff
,"16K bytes");
201 sprintf(asBuff
,"32K bytes");
204 sprintf(asBuff
,"64K bytes");
207 sprintf(asBuff
,"128K bytes");
210 sprintf(asBuff
,"256K bytes");
213 sprintf(asBuff
,"96K bytes");
216 sprintf(asBuff
,"512K bytes");
219 PrintAndLog("Internal SRAM Size: %s",asBuff
);
220 switch((iChipID
&0xFF00000)>>20)
223 sprintf(asBuff
,"AT91SAM9xx Series");
226 sprintf(asBuff
,"AT91SAM9XExx Series");
229 sprintf(asBuff
,"AT91x34 Series");
232 sprintf(asBuff
,"CAP7 Series");
235 sprintf(asBuff
,"CAP9 Series");
238 sprintf(asBuff
,"CAP11 Series");
241 sprintf(asBuff
,"AT91x40 Series");
244 sprintf(asBuff
,"AT91x42 Series");
247 sprintf(asBuff
,"AT91x55 Series");
250 sprintf(asBuff
,"AT91SAM7Axx Series");
253 sprintf(asBuff
,"AT91SAM7AQxx Series");
256 sprintf(asBuff
,"AT91x63 Series");
259 sprintf(asBuff
,"AT91SAM7Sxx Series");
262 sprintf(asBuff
,"AT91SAM7XCxx Series");
265 sprintf(asBuff
,"AT91SAM7SExx Series");
268 sprintf(asBuff
,"AT91SAM7Lxx Series");
271 sprintf(asBuff
,"AT91SAM7Xxx Series");
274 sprintf(asBuff
,"AT91x92 Series");
277 sprintf(asBuff
,"AT75Cxx Series");
280 PrintAndLog("Architecture Identifier: %s",asBuff
);
281 switch((iChipID
&0x70000000)>>28)
284 sprintf(asBuff
,"ROM");
287 sprintf(asBuff
,"ROMless or on-chip Flash");
290 sprintf(asBuff
,"SRAM emulating ROM");
293 sprintf(asBuff
,"Embedded Flash Memory");
296 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
299 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
302 int CmdDetectReader(const char *Cmd
)
304 UsbCommand c
={CMD_LISTEN_READER_FIELD
};
305 // 'l' means LF - 125/134 kHz
308 } else if (*Cmd
== 'h') {
310 } else if (*Cmd
!= '\0') {
311 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
319 int CmdFPGAOff(const char *Cmd
)
321 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
326 int CmdLCD(const char *Cmd
)
330 UsbCommand c
={CMD_LCD
};
331 sscanf(Cmd
, "%x %d", &i
, &j
);
333 c
.arg
[0] = i
& 0x1ff;
339 int CmdLCDReset(const char *Cmd
)
341 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
346 int CmdReadmem(const char *Cmd
)
348 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
353 int CmdReset(const char *Cmd
)
355 UsbCommand c
= {CMD_HARDWARE_RESET
};
361 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
364 int CmdSetDivisor(const char *Cmd
)
366 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
367 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
368 PrintAndLog("divisor must be between 19 and 255");
371 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
376 int CmdSetMux(const char *Cmd
)
378 UsbCommand c
={CMD_SET_ADC_MUX
};
379 if (strcmp(Cmd
, "lopkd") == 0) {
381 } else if (strcmp(Cmd
, "loraw") == 0) {
383 } else if (strcmp(Cmd
, "hipkd") == 0) {
385 } else if (strcmp(Cmd
, "hiraw") == 0) {
392 int CmdTune(const char *Cmd
)
394 return CmdTuneSamples(Cmd
);
397 int CmdVersion(const char *Cmd
)
399 UsbCommand c
= {CMD_VERSION
};
402 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
403 lookupChipID(resp
.arg
[0]);
408 static command_t CommandTable
[] =
410 {"help", CmdHelp
, 1, "This help"},
411 {"detectreader", CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
412 {"fpgaoff", CmdFPGAOff
, 0, "Set FPGA off"},
413 {"lcd", CmdLCD
, 0, "<HEX command> <count> -- Send command/data to LCD"},
414 {"lcdreset", CmdLCDReset
, 0, "Hardware reset LCD"},
415 {"readmem", CmdReadmem
, 0, "[address] -- Read memory at decimal address from flash"},
416 {"reset", CmdReset
, 0, "Reset the Proxmark3"},
417 {"setlfdivisor", CmdSetDivisor
, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
418 {"setmux", CmdSetMux
, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
419 {"tune", CmdTune
, 0, "Measure antenna tuning"},
420 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
421 {NULL
, NULL
, 0, NULL
}
424 int CmdHW(const char *Cmd
)
426 CmdsParse(CommandTable
, Cmd
);
430 int CmdHelp(const char *Cmd
)
432 CmdsHelp(CommandTable
);