]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
78695346d3e20b00f118a1671ff6bdac8a1c88ba
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
, uint32_t mem_used
)
29 uint32_t mem_avail
= 0;
34 sprintf(asBuff
,"AT91SAM7S512 Rev A");
37 sprintf(asBuff
,"AT91SAM7S512 Rev B");
40 sprintf(asBuff
,"AT91SAM7S256 Rev A");
43 sprintf(asBuff
,"AT91SAM7S256 Rev B");
46 sprintf(asBuff
,"AT91SAM7S256 Rev C");
49 sprintf(asBuff
,"AT91SAM7S256 Rev D");
52 sprintf(asBuff
,"AT91SAM7S128 Rev A");
55 sprintf(asBuff
,"AT91SAM7S128 Rev B");
58 sprintf(asBuff
,"AT91SAM7S128 Rev C");
61 sprintf(asBuff
,"AT91SAM7S128 Rev D");
64 sprintf(asBuff
,"AT91SAM7S64 Rev A");
67 sprintf(asBuff
,"AT91SAM7S64 Rev B");
70 sprintf(asBuff
,"AT91SAM7S64 Rev C");
73 sprintf(asBuff
,"AT91SAM7S321 Rev A");
76 sprintf(asBuff
,"AT91SAM7S32 Rev A");
79 sprintf(asBuff
,"AT91SAM7S32 Rev B");
82 sprintf(asBuff
,"AT9SAM7S161 Rev A");
85 sprintf(asBuff
,"AT91SAM7S16 Rev A");
88 PrintAndLog("uC: %s",asBuff
);
89 switch((iChipID
&0xE0)>>5)
92 sprintf(asBuff
,"ARM946ES");
95 sprintf(asBuff
,"ARM7TDMI");
98 sprintf(asBuff
,"ARM920T");
101 sprintf(asBuff
,"ARM926EJS");
104 PrintAndLog("Embedded Processor: %s",asBuff
);
105 switch((iChipID
&0xF00)>>8)
138 PrintAndLog("Nonvolatile Program Memory Size: %dK bytes. Used: %d bytes (%2.0f\%). Free: %d bytes (%2.0f\%).",
141 mem_avail
== 0 ? 0 : (float)mem_used
/(mem_avail
*1024)*100,
142 mem_avail
*1024 - mem_used
,
143 mem_avail
== 0 ? 0 : (float)(mem_avail
*1024-mem_used
)/(mem_avail
*1024)*100
145 switch((iChipID
&0xF000)>>12)
148 sprintf(asBuff
,"None");
151 sprintf(asBuff
,"8K bytes");
154 sprintf(asBuff
,"16K bytes");
157 sprintf(asBuff
,"32K bytes");
160 sprintf(asBuff
,"64K bytes");
163 sprintf(asBuff
,"128K bytes");
166 sprintf(asBuff
,"256K bytes");
169 sprintf(asBuff
,"512K bytes");
172 sprintf(asBuff
,"1024K bytes");
175 sprintf(asBuff
,"2048K bytes");
178 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
179 switch((iChipID
&0xF0000)>>16)
182 sprintf(asBuff
,"1K bytes");
185 sprintf(asBuff
,"2K bytes");
188 sprintf(asBuff
,"6K bytes");
191 sprintf(asBuff
,"112K bytes");
194 sprintf(asBuff
,"4K bytes");
197 sprintf(asBuff
,"80K bytes");
200 sprintf(asBuff
,"160K bytes");
203 sprintf(asBuff
,"8K bytes");
206 sprintf(asBuff
,"16K bytes");
209 sprintf(asBuff
,"32K bytes");
212 sprintf(asBuff
,"64K bytes");
215 sprintf(asBuff
,"128K bytes");
218 sprintf(asBuff
,"256K bytes");
221 sprintf(asBuff
,"96K bytes");
224 sprintf(asBuff
,"512K bytes");
227 PrintAndLog("Internal SRAM Size: %s",asBuff
);
228 switch((iChipID
&0xFF00000)>>20)
231 sprintf(asBuff
,"AT91SAM9xx Series");
234 sprintf(asBuff
,"AT91SAM9XExx Series");
237 sprintf(asBuff
,"AT91x34 Series");
240 sprintf(asBuff
,"CAP7 Series");
243 sprintf(asBuff
,"CAP9 Series");
246 sprintf(asBuff
,"CAP11 Series");
249 sprintf(asBuff
,"AT91x40 Series");
252 sprintf(asBuff
,"AT91x42 Series");
255 sprintf(asBuff
,"AT91x55 Series");
258 sprintf(asBuff
,"AT91SAM7Axx Series");
261 sprintf(asBuff
,"AT91SAM7AQxx Series");
264 sprintf(asBuff
,"AT91x63 Series");
267 sprintf(asBuff
,"AT91SAM7Sxx Series");
270 sprintf(asBuff
,"AT91SAM7XCxx Series");
273 sprintf(asBuff
,"AT91SAM7SExx Series");
276 sprintf(asBuff
,"AT91SAM7Lxx Series");
279 sprintf(asBuff
,"AT91SAM7Xxx Series");
282 sprintf(asBuff
,"AT91x92 Series");
285 sprintf(asBuff
,"AT75Cxx Series");
288 PrintAndLog("Architecture Identifier: %s",asBuff
);
289 switch((iChipID
&0x70000000)>>28)
292 sprintf(asBuff
,"ROM");
295 sprintf(asBuff
,"ROMless or on-chip Flash");
298 sprintf(asBuff
,"SRAM emulating ROM");
301 sprintf(asBuff
,"Embedded Flash Memory");
304 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
307 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
310 int CmdDetectReader(const char *Cmd
)
312 UsbCommand c
={CMD_LISTEN_READER_FIELD
};
313 // 'l' means LF - 125/134 kHz
316 } else if (*Cmd
== 'h') {
318 } else if (*Cmd
!= '\0') {
319 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
327 int CmdFPGAOff(const char *Cmd
)
329 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
334 int CmdLCD(const char *Cmd
)
338 UsbCommand c
={CMD_LCD
};
339 sscanf(Cmd
, "%x %d", &i
, &j
);
341 c
.arg
[0] = i
& 0x1ff;
347 int CmdLCDReset(const char *Cmd
)
349 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
354 int CmdReadmem(const char *Cmd
)
356 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
361 int CmdReset(const char *Cmd
)
363 UsbCommand c
= {CMD_HARDWARE_RESET
};
369 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
372 int CmdSetDivisor(const char *Cmd
)
374 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
375 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
376 PrintAndLog("divisor must be between 19 and 255");
379 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
384 int CmdSetMux(const char *Cmd
)
386 UsbCommand c
={CMD_SET_ADC_MUX
};
387 if (strcmp(Cmd
, "lopkd") == 0) {
389 } else if (strcmp(Cmd
, "loraw") == 0) {
391 } else if (strcmp(Cmd
, "hipkd") == 0) {
393 } else if (strcmp(Cmd
, "hiraw") == 0) {
400 int CmdTune(const char *Cmd
)
402 return CmdTuneSamples(Cmd
);
405 int CmdVersion(const char *Cmd
)
407 UsbCommand c
= {CMD_VERSION
};
410 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
411 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
416 static command_t CommandTable
[] =
418 {"help", CmdHelp
, 1, "This help"},
419 {"detectreader", CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
420 {"fpgaoff", CmdFPGAOff
, 0, "Set FPGA off"},
421 {"lcd", CmdLCD
, 0, "<HEX command> <count> -- Send command/data to LCD"},
422 {"lcdreset", CmdLCDReset
, 0, "Hardware reset LCD"},
423 {"readmem", CmdReadmem
, 0, "[address] -- Read memory at decimal address from flash"},
424 {"reset", CmdReset
, 0, "Reset the Proxmark3"},
425 {"setlfdivisor", CmdSetDivisor
, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
426 {"setmux", CmdSetMux
, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
427 {"tune", CmdTune
, 0, "Measure antenna tuning"},
428 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
429 {NULL
, NULL
, 0, NULL
}
432 int CmdHW(const char *Cmd
)
434 CmdsParse(CommandTable
, Cmd
);
438 int CmdHelp(const char *Cmd
)
440 CmdsHelp(CommandTable
);