]>
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"
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
)
408 clearCommandBuffer();
409 UsbCommand c
= {CMD_VERSION
};
410 static UsbCommand resp
= {0, {0, 0, 0}};
412 if (resp
.arg
[0] == 0 && resp
.arg
[1] == 0) { // no cached information available
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]);
420 PrintAndLog("[[[ Cached information ]]]\n");
421 PrintAndLog("Prox/RFID mark3 RFID instrument");
422 PrintAndLog((char*)resp
.d
.asBytes
);
423 lookupChipID(resp
.arg
[0], resp
.arg
[1]);
429 int CmdStatus(const char *Cmd
)
431 UsbCommand c
= {CMD_STATUS
};
436 int CmdPing(const char *Cmd
)
438 clearCommandBuffer();
440 UsbCommand c
= {CMD_PING
};
442 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
443 PrintAndLog("Ping successfull");
445 PrintAndLog("Ping failed");
450 static command_t CommandTable
[] =
452 {"help", CmdHelp
, 1, "This help"},
453 {"detectreader", CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
454 {"fpgaoff", CmdFPGAOff
, 0, "Set FPGA off"},
455 {"lcd", CmdLCD
, 0, "<HEX command> <count> -- Send command/data to LCD"},
456 {"lcdreset", CmdLCDReset
, 0, "Hardware reset LCD"},
457 {"readmem", CmdReadmem
, 0, "[address] -- Read memory at decimal address from flash"},
458 {"reset", CmdReset
, 0, "Reset the Proxmark3"},
459 {"setlfdivisor", CmdSetDivisor
, 0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
460 {"setmux", CmdSetMux
, 0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
461 {"tune", CmdTune
, 0, "Measure antenna tuning"},
462 {"version", CmdVersion
, 0, "Show version information about the connected Proxmark"},
463 {"status", CmdStatus
, 0, "Show runtime status information about the connected Proxmark"},
464 {"ping", CmdPing
, 0, "Test if the pm3 is responsive"},
465 {NULL
, NULL
, 0, NULL
}
468 int CmdHW(const char *Cmd
)
470 CmdsParse(CommandTable
, Cmd
);
474 int CmdHelp(const char *Cmd
)
476 CmdsHelp(CommandTable
);