]>
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
)
33 sprintf(asBuff
,"AT91SAM7S512 Rev A");
36 sprintf(asBuff
,"AT91SAM7S512 Rev B");
39 sprintf(asBuff
,"AT91SAM7S256 Rev A");
42 sprintf(asBuff
,"AT91SAM7S256 Rev B");
45 sprintf(asBuff
,"AT91SAM7S256 Rev C");
48 sprintf(asBuff
,"AT91SAM7S256 Rev D");
51 sprintf(asBuff
,"AT91SAM7S128 Rev A");
54 sprintf(asBuff
,"AT91SAM7S128 Rev B");
57 sprintf(asBuff
,"AT91SAM7S128 Rev C");
60 sprintf(asBuff
,"AT91SAM7S128 Rev D");
63 sprintf(asBuff
,"AT91SAM7S64 Rev A");
66 sprintf(asBuff
,"AT91SAM7S64 Rev B");
69 sprintf(asBuff
,"AT91SAM7S64 Rev C");
72 sprintf(asBuff
,"AT91SAM7S321 Rev A");
75 sprintf(asBuff
,"AT91SAM7S32 Rev A");
78 sprintf(asBuff
,"AT91SAM7S32 Rev B");
81 sprintf(asBuff
,"AT9SAM7S161 Rev A");
84 sprintf(asBuff
,"AT91SAM7S16 Rev A");
87 PrintAndLog("uC: %s",asBuff
);
88 switch((iChipID
&0xE0)>>5)
91 sprintf(asBuff
,"ARM946ES");
94 sprintf(asBuff
,"ARM7TDMI");
97 sprintf(asBuff
,"ARM920T");
100 sprintf(asBuff
,"ARM926EJS");
103 PrintAndLog("Embedded Processor: %s",asBuff
);
104 switch((iChipID
&0xF00)>>8)
107 sprintf(asBuff
,"None");
110 sprintf(asBuff
,"8K bytes");
113 sprintf(asBuff
,"16K bytes");
116 sprintf(asBuff
,"32K bytes");
119 sprintf(asBuff
,"64K bytes");
122 sprintf(asBuff
,"128K bytes");
125 sprintf(asBuff
,"256K bytes");
128 sprintf(asBuff
,"512K bytes");
131 sprintf(asBuff
,"1024K bytes");
134 sprintf(asBuff
,"2048K bytes");
137 PrintAndLog("Nonvolatile Program Memory Size: %s",asBuff
);
138 switch((iChipID
&0xF000)>>12)
141 sprintf(asBuff
,"None");
144 sprintf(asBuff
,"8K bytes");
147 sprintf(asBuff
,"16K bytes");
150 sprintf(asBuff
,"32K bytes");
153 sprintf(asBuff
,"64K bytes");
156 sprintf(asBuff
,"128K bytes");
159 sprintf(asBuff
,"256K bytes");
162 sprintf(asBuff
,"512K bytes");
165 sprintf(asBuff
,"1024K bytes");
168 sprintf(asBuff
,"2048K bytes");
171 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
172 switch((iChipID
&0xF0000)>>16)
175 sprintf(asBuff
,"1K bytes");
178 sprintf(asBuff
,"2K bytes");
181 sprintf(asBuff
,"6K bytes");
184 sprintf(asBuff
,"112K bytes");
187 sprintf(asBuff
,"4K bytes");
190 sprintf(asBuff
,"80K bytes");
193 sprintf(asBuff
,"160K bytes");
196 sprintf(asBuff
,"8K bytes");
199 sprintf(asBuff
,"16K bytes");
202 sprintf(asBuff
,"32K bytes");
205 sprintf(asBuff
,"64K bytes");
208 sprintf(asBuff
,"128K bytes");
211 sprintf(asBuff
,"256K bytes");
214 sprintf(asBuff
,"96K bytes");
217 sprintf(asBuff
,"512K bytes");
220 PrintAndLog("Internal SRAM Size: %s",asBuff
);
221 switch((iChipID
&0xFF00000)>>20)
224 sprintf(asBuff
,"AT91SAM9xx Series");
227 sprintf(asBuff
,"AT91SAM9XExx Series");
230 sprintf(asBuff
,"AT91x34 Series");
233 sprintf(asBuff
,"CAP7 Series");
236 sprintf(asBuff
,"CAP9 Series");
239 sprintf(asBuff
,"CAP11 Series");
242 sprintf(asBuff
,"AT91x40 Series");
245 sprintf(asBuff
,"AT91x42 Series");
248 sprintf(asBuff
,"AT91x55 Series");
251 sprintf(asBuff
,"AT91SAM7Axx Series");
254 sprintf(asBuff
,"AT91SAM7AQxx Series");
257 sprintf(asBuff
,"AT91x63 Series");
260 sprintf(asBuff
,"AT91SAM7Sxx Series");
263 sprintf(asBuff
,"AT91SAM7XCxx Series");
266 sprintf(asBuff
,"AT91SAM7SExx Series");
269 sprintf(asBuff
,"AT91SAM7Lxx Series");
272 sprintf(asBuff
,"AT91SAM7Xxx Series");
275 sprintf(asBuff
,"AT91x92 Series");
278 sprintf(asBuff
,"AT75Cxx Series");
281 PrintAndLog("Architecture Identifier: %s",asBuff
);
282 switch((iChipID
&0x70000000)>>28)
285 sprintf(asBuff
,"ROM");
288 sprintf(asBuff
,"ROMless or on-chip Flash");
291 sprintf(asBuff
,"SRAM emulating ROM");
294 sprintf(asBuff
,"Embedded Flash Memory");
297 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
300 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
303 int CmdDetectReader(const char *Cmd
)
305 UsbCommand c
={CMD_LISTEN_READER_FIELD
};
306 // 'l' means LF - 125/134 kHz
309 } else if (*Cmd
== 'h') {
311 } else if (*Cmd
!= '\0') {
312 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
320 int CmdFPGAOff(const char *Cmd
)
322 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
327 int CmdLCD(const char *Cmd
)
331 UsbCommand c
={CMD_LCD
};
332 sscanf(Cmd
, "%x %d", &i
, &j
);
334 c
.arg
[0] = i
& 0x1ff;
340 int CmdLCDReset(const char *Cmd
)
342 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
347 int CmdReadmem(const char *Cmd
)
349 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
354 int CmdReset(const char *Cmd
)
356 UsbCommand c
= {CMD_HARDWARE_RESET
};
362 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
365 int CmdSetDivisor(const char *Cmd
)
367 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
368 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
369 PrintAndLog("divisor must be between 19 and 255");
372 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
377 int CmdSetMux(const char *Cmd
)
379 UsbCommand c
={CMD_SET_ADC_MUX
};
380 if (strcmp(Cmd
, "lopkd") == 0) {
382 } else if (strcmp(Cmd
, "loraw") == 0) {
384 } else if (strcmp(Cmd
, "hipkd") == 0) {
386 } else if (strcmp(Cmd
, "hiraw") == 0) {
393 int CmdTune(const char *Cmd
)
395 return CmdTuneSamples(Cmd
);
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
);