]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
f994e938778cae8dffa590432240a053173e78d0
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 //-----------------------------------------------------------------------------
19 #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 uint32_t mem_avail
= 0;
35 sprintf(asBuff
,"AT91SAM7S512 Rev A");
38 sprintf(asBuff
,"AT91SAM7S512 Rev B");
41 sprintf(asBuff
,"AT91SAM7S256 Rev A");
44 sprintf(asBuff
,"AT91SAM7S256 Rev B");
47 sprintf(asBuff
,"AT91SAM7S256 Rev C");
50 sprintf(asBuff
,"AT91SAM7S256 Rev D");
53 sprintf(asBuff
,"AT91SAM7S128 Rev A");
56 sprintf(asBuff
,"AT91SAM7S128 Rev B");
59 sprintf(asBuff
,"AT91SAM7S128 Rev C");
62 sprintf(asBuff
,"AT91SAM7S128 Rev D");
65 sprintf(asBuff
,"AT91SAM7S64 Rev A");
68 sprintf(asBuff
,"AT91SAM7S64 Rev B");
71 sprintf(asBuff
,"AT91SAM7S64 Rev C");
74 sprintf(asBuff
,"AT91SAM7S321 Rev A");
77 sprintf(asBuff
,"AT91SAM7S32 Rev A");
80 sprintf(asBuff
,"AT91SAM7S32 Rev B");
83 sprintf(asBuff
,"AT9SAM7S161 Rev A");
86 sprintf(asBuff
,"AT91SAM7S16 Rev A");
89 PrintAndLog("uC: %s",asBuff
);
90 switch((iChipID
&0xE0)>>5)
93 sprintf(asBuff
,"ARM946ES");
96 sprintf(asBuff
,"ARM7TDMI");
99 sprintf(asBuff
,"ARM920T");
102 sprintf(asBuff
,"ARM926EJS");
105 PrintAndLog("Embedded Processor: %s",asBuff
);
106 switch((iChipID
&0xF00)>>8)
139 PrintAndLog("Nonvolatile Program Memory Size: %dK bytes. Used: %d bytes (%2.0f\%). Free: %d bytes (%2.0f\%).",
142 mem_avail
== 0 ? 0 : (float)mem_used
/(mem_avail
*1024)*100,
143 mem_avail
*1024 - mem_used
,
144 mem_avail
== 0 ? 0 : (float)(mem_avail
*1024-mem_used
)/(mem_avail
*1024)*100
146 switch((iChipID
&0xF000)>>12)
149 sprintf(asBuff
,"None");
152 sprintf(asBuff
,"8K bytes");
155 sprintf(asBuff
,"16K bytes");
158 sprintf(asBuff
,"32K bytes");
161 sprintf(asBuff
,"64K bytes");
164 sprintf(asBuff
,"128K bytes");
167 sprintf(asBuff
,"256K bytes");
170 sprintf(asBuff
,"512K bytes");
173 sprintf(asBuff
,"1024K bytes");
176 sprintf(asBuff
,"2048K bytes");
179 PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
);
180 switch((iChipID
&0xF0000)>>16)
183 sprintf(asBuff
,"1K bytes");
186 sprintf(asBuff
,"2K bytes");
189 sprintf(asBuff
,"6K bytes");
192 sprintf(asBuff
,"112K bytes");
195 sprintf(asBuff
,"4K bytes");
198 sprintf(asBuff
,"80K bytes");
201 sprintf(asBuff
,"160K bytes");
204 sprintf(asBuff
,"8K bytes");
207 sprintf(asBuff
,"16K bytes");
210 sprintf(asBuff
,"32K bytes");
213 sprintf(asBuff
,"64K bytes");
216 sprintf(asBuff
,"128K bytes");
219 sprintf(asBuff
,"256K bytes");
222 sprintf(asBuff
,"96K bytes");
225 sprintf(asBuff
,"512K bytes");
228 PrintAndLog("Internal SRAM Size: %s",asBuff
);
229 switch((iChipID
&0xFF00000)>>20)
232 sprintf(asBuff
,"AT91SAM9xx Series");
235 sprintf(asBuff
,"AT91SAM9XExx Series");
238 sprintf(asBuff
,"AT91x34 Series");
241 sprintf(asBuff
,"CAP7 Series");
244 sprintf(asBuff
,"CAP9 Series");
247 sprintf(asBuff
,"CAP11 Series");
250 sprintf(asBuff
,"AT91x40 Series");
253 sprintf(asBuff
,"AT91x42 Series");
256 sprintf(asBuff
,"AT91x55 Series");
259 sprintf(asBuff
,"AT91SAM7Axx Series");
262 sprintf(asBuff
,"AT91SAM7AQxx Series");
265 sprintf(asBuff
,"AT91x63 Series");
268 sprintf(asBuff
,"AT91SAM7Sxx Series");
271 sprintf(asBuff
,"AT91SAM7XCxx Series");
274 sprintf(asBuff
,"AT91SAM7SExx Series");
277 sprintf(asBuff
,"AT91SAM7Lxx Series");
280 sprintf(asBuff
,"AT91SAM7Xxx Series");
283 sprintf(asBuff
,"AT91x92 Series");
286 sprintf(asBuff
,"AT75Cxx Series");
289 PrintAndLog("Architecture Identifier: %s",asBuff
);
290 switch((iChipID
&0x70000000)>>28)
293 sprintf(asBuff
,"ROM");
296 sprintf(asBuff
,"ROMless or on-chip Flash");
299 sprintf(asBuff
,"SRAM emulating ROM");
302 sprintf(asBuff
,"Embedded Flash Memory");
305 sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size");
308 PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
);
311 int CmdDetectReader(const char *Cmd
)
313 UsbCommand c
={CMD_LISTEN_READER_FIELD
};
314 // 'l' means LF - 125/134 kHz
317 } else if (*Cmd
== 'h') {
319 } else if (*Cmd
!= '\0') {
320 PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'");
328 int CmdFPGAOff(const char *Cmd
)
330 UsbCommand c
= {CMD_FPGA_MAJOR_MODE_OFF
};
335 int CmdLCD(const char *Cmd
)
339 UsbCommand c
={CMD_LCD
};
340 sscanf(Cmd
, "%x %d", &i
, &j
);
342 c
.arg
[0] = i
& 0x1ff;
348 int CmdLCDReset(const char *Cmd
)
350 UsbCommand c
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}};
355 int CmdReadmem(const char *Cmd
)
357 UsbCommand c
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}};
362 int CmdReset(const char *Cmd
)
364 UsbCommand c
= {CMD_HARDWARE_RESET
};
370 * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
373 int CmdSetDivisor(const char *Cmd
)
375 UsbCommand c
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}};
376 if (c
.arg
[0] < 19 || c
.arg
[0] > 255) {
377 PrintAndLog("divisor must be between 19 and 255");
380 PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1));
385 int CmdSetMux(const char *Cmd
)
387 UsbCommand c
={CMD_SET_ADC_MUX
};
388 if (strcmp(Cmd
, "lopkd") == 0) {
390 } else if (strcmp(Cmd
, "loraw") == 0) {
392 } else if (strcmp(Cmd
, "hipkd") == 0) {
394 } else if (strcmp(Cmd
, "hiraw") == 0) {
401 int CmdTune(const char *Cmd
)
403 return CmdTuneSamples(Cmd
);
406 int CmdVersion(const char *Cmd
)
409 clearCommandBuffer();
410 UsbCommand c
= {CMD_VERSION
};
411 UsbCommand resp
= {0, {0, 0, 0}};
414 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
415 PrintAndLog("Prox/RFID mark3 RFID instrument");
416 PrintAndLog((char*)resp
.d
.asBytes
);
417 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
422 int CmdStatus(const char *Cmd
)
424 clearCommandBuffer();
425 UsbCommand c
= {CMD_STATUS
};
427 if (!WaitForResponseTimeout(CMD_ACK
, &c
, 1900)) {
428 PrintAndLog("Status command failed. USB Speed Test timed out");
434 int CmdPing(const char *Cmd
)
436 clearCommandBuffer();
438 UsbCommand c
= {CMD_PING
};
440 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
441 PrintAndLog("Ping successful");
443 PrintAndLog("Ping failed");
448 static command_t CommandTable
[] =
450 {"help", CmdHelp
, 1, "This help"},
451 {"detectreader", CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
452 {"fpgaoff", CmdFPGAOff
, 0, "Set FPGA off"},
453 {"lcd", CmdLCD
, 0, "<HEX command> <count> -- Send command/data to LCD"},
454 {"lcdreset", CmdLCDReset
, 0, "Hardware reset LCD"},
455 {"readmem", CmdReadmem
, 0, "[address] -- Read memory at decimal address from flash"},
456 {"reset", CmdReset
, 0, "Reset the Proxmark3"},
457 {"setlfdivisor", CmdSetDivisor
, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
458 {"setmux", CmdSetMux
, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
459 {"tune", CmdTune
, 0, "['l'|'h'] -- Measure antenna tuning (option 'l' or 'h' to limit to LF or HF)"},
460 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
461 {"status", CmdStatus
, 0, "Show runtime status information about the connected Proxmark"},
462 {"ping", CmdPing
, 0, "Test if the pm3 is responsive"},
463 {NULL
, NULL
, 0, NULL
}
466 int CmdHW(const char *Cmd
)
468 CmdsParse(CommandTable
, Cmd
);
472 int CmdHelp(const char *Cmd
)
474 CmdsHelp(CommandTable
);