]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhw.c
b6a0d11f2bbd27852bd35cf2384de46630563950
   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" 
  24 static uint32_t hw_capabilities 
= 0; 
  26 static int CmdHelp(const char *Cmd
); 
  28 static void lookupChipID(uint32_t iChipID
, uint32_t mem_used
) 
  31         uint32_t mem_avail 
= 0; 
  36                         sprintf(asBuff
,"AT91SAM7S512 Rev A"); 
  39                         sprintf(asBuff
,"AT91SAM7S512 Rev B"); 
  42                         sprintf(asBuff
,"AT91SAM7S256 Rev A"); 
  45                         sprintf(asBuff
,"AT91SAM7S256 Rev B"); 
  48                         sprintf(asBuff
,"AT91SAM7S256 Rev C"); 
  51                         sprintf(asBuff
,"AT91SAM7S256 Rev D"); 
  54                         sprintf(asBuff
,"AT91SAM7S128 Rev A"); 
  57                         sprintf(asBuff
,"AT91SAM7S128 Rev B"); 
  60                         sprintf(asBuff
,"AT91SAM7S128 Rev C"); 
  63                         sprintf(asBuff
,"AT91SAM7S128 Rev D"); 
  66                         sprintf(asBuff
,"AT91SAM7S64 Rev A"); 
  69                         sprintf(asBuff
,"AT91SAM7S64 Rev B"); 
  72                         sprintf(asBuff
,"AT91SAM7S64 Rev C"); 
  75                         sprintf(asBuff
,"AT91SAM7S321 Rev A"); 
  78                         sprintf(asBuff
,"AT91SAM7S32 Rev A"); 
  81                         sprintf(asBuff
,"AT91SAM7S32 Rev B"); 
  84                         sprintf(asBuff
,"AT9SAM7S161 Rev A"); 
  87                         sprintf(asBuff
,"AT91SAM7S16 Rev A"); 
  90         PrintAndLog("uC: %s",asBuff
); 
  91         switch((iChipID
&0xE0)>>5) 
  94                         sprintf(asBuff
,"ARM946ES"); 
  97                         sprintf(asBuff
,"ARM7TDMI"); 
 100                         sprintf(asBuff
,"ARM920T"); 
 103                         sprintf(asBuff
,"ARM926EJS"); 
 106         PrintAndLog("Embedded Processor: %s",asBuff
); 
 107         switch((iChipID
&0xF00)>>8) 
 140         PrintAndLog("Nonvolatile Program Memory Size: %dK bytes. Used: %d bytes (%2.0f\%). Free: %d bytes (%2.0f\%).",  
 143                                 mem_avail 
== 0 ? 0 : (float)mem_used
/(mem_avail
*1024)*100, 
 144                                 mem_avail
*1024 - mem_used
, 
 145                                 mem_avail 
== 0 ? 0 : (float)(mem_avail
*1024-mem_used
)/(mem_avail
*1024)*100 
 147         switch((iChipID
&0xF000)>>12) 
 150                         sprintf(asBuff
,"None"); 
 153                         sprintf(asBuff
,"8K bytes"); 
 156                         sprintf(asBuff
,"16K bytes"); 
 159                         sprintf(asBuff
,"32K bytes"); 
 162                         sprintf(asBuff
,"64K bytes"); 
 165                         sprintf(asBuff
,"128K bytes"); 
 168                         sprintf(asBuff
,"256K bytes"); 
 171                         sprintf(asBuff
,"512K bytes"); 
 174                         sprintf(asBuff
,"1024K bytes"); 
 177                         sprintf(asBuff
,"2048K bytes"); 
 180         PrintAndLog("Second Nonvolatile Program Memory Size: %s",asBuff
); 
 181         switch((iChipID
&0xF0000)>>16) 
 184                         sprintf(asBuff
,"1K bytes"); 
 187                         sprintf(asBuff
,"2K bytes"); 
 190                         sprintf(asBuff
,"6K bytes"); 
 193                         sprintf(asBuff
,"112K bytes"); 
 196                         sprintf(asBuff
,"4K bytes"); 
 199                         sprintf(asBuff
,"80K bytes"); 
 202                         sprintf(asBuff
,"160K bytes"); 
 205                         sprintf(asBuff
,"8K bytes"); 
 208                         sprintf(asBuff
,"16K bytes"); 
 211                         sprintf(asBuff
,"32K bytes"); 
 214                         sprintf(asBuff
,"64K bytes"); 
 217                         sprintf(asBuff
,"128K bytes"); 
 220                         sprintf(asBuff
,"256K bytes"); 
 223                         sprintf(asBuff
,"96K bytes"); 
 226                         sprintf(asBuff
,"512K bytes"); 
 229         PrintAndLog("Internal SRAM Size: %s",asBuff
); 
 230         switch((iChipID
&0xFF00000)>>20) 
 233                         sprintf(asBuff
,"AT91SAM9xx Series"); 
 236                         sprintf(asBuff
,"AT91SAM9XExx Series"); 
 239                         sprintf(asBuff
,"AT91x34 Series"); 
 242                         sprintf(asBuff
,"CAP7 Series"); 
 245                         sprintf(asBuff
,"CAP9 Series"); 
 248                         sprintf(asBuff
,"CAP11 Series"); 
 251                         sprintf(asBuff
,"AT91x40 Series"); 
 254                         sprintf(asBuff
,"AT91x42 Series"); 
 257                         sprintf(asBuff
,"AT91x55 Series"); 
 260                         sprintf(asBuff
,"AT91SAM7Axx Series"); 
 263                         sprintf(asBuff
,"AT91SAM7AQxx Series"); 
 266                         sprintf(asBuff
,"AT91x63 Series"); 
 269                         sprintf(asBuff
,"AT91SAM7Sxx Series"); 
 272                         sprintf(asBuff
,"AT91SAM7XCxx Series"); 
 275                         sprintf(asBuff
,"AT91SAM7SExx Series"); 
 278                         sprintf(asBuff
,"AT91SAM7Lxx Series"); 
 281                         sprintf(asBuff
,"AT91SAM7Xxx Series"); 
 284                         sprintf(asBuff
,"AT91x92 Series"); 
 287                         sprintf(asBuff
,"AT75Cxx Series"); 
 290         PrintAndLog("Architecture Identifier: %s",asBuff
); 
 291         switch((iChipID
&0x70000000)>>28) 
 294                         sprintf(asBuff
,"ROM"); 
 297                         sprintf(asBuff
,"ROMless or on-chip Flash"); 
 300                         sprintf(asBuff
,"SRAM emulating ROM"); 
 303                         sprintf(asBuff
,"Embedded Flash Memory"); 
 306                         sprintf(asBuff
,"ROM and Embedded Flash Memory\nNVPSIZ is ROM size\nNVPSIZ2 is Flash size"); 
 309         PrintAndLog("Nonvolatile Program Memory Type: %s",asBuff
); 
 312 int CmdDetectReader(const char *Cmd
) 
 314   UsbCommand c
={CMD_LISTEN_READER_FIELD
}; 
 315   // 'l' means LF - 125/134 kHz 
 318   } else if (*Cmd 
== 'h') { 
 320   } else if (*Cmd 
!= '\0') { 
 321     PrintAndLog("use 'detectreader' or 'detectreader l' or 'detectreader h'"); 
 329 int CmdFPGAOff(const char *Cmd
) 
 331   UsbCommand c 
= {CMD_FPGA_MAJOR_MODE_OFF
}; 
 336 int CmdLCD(const char *Cmd
) 
 340   UsbCommand c
={CMD_LCD
}; 
 341   sscanf(Cmd
, "%x %d", &i
, &j
); 
 343     c
.arg
[0] = i 
& 0x1ff; 
 349 int CmdLCDReset(const char *Cmd
) 
 351   UsbCommand c 
= {CMD_LCD_RESET
, {strtol(Cmd
, NULL
, 0), 0, 0}}; 
 356 int CmdReadmem(const char *Cmd
) 
 358   UsbCommand c 
= {CMD_READ_MEM
, {strtol(Cmd
, NULL
, 0), 0, 0}}; 
 363 int CmdReset(const char *Cmd
) 
 365   UsbCommand c 
= {CMD_HARDWARE_RESET
}; 
 371  * Sets the divisor for LF frequency clock: lets the user choose any LF frequency below 
 374 int CmdSetDivisor(const char *Cmd
) 
 376   UsbCommand c 
= {CMD_SET_LF_DIVISOR
, {strtol(Cmd
, NULL
, 0), 0, 0}}; 
 377   if (c
.arg
[0] < 19 || c
.arg
[0] > 255) { 
 378     PrintAndLog("divisor must be between 19 and 255"); 
 381     PrintAndLog("Divisor set, expected freq=%dHz", 12000000 / (c
.arg
[0]+1)); 
 386 int CmdSetMux(const char *Cmd
) 
 388   UsbCommand c
={CMD_SET_ADC_MUX
}; 
 389   if (strcmp(Cmd
, "lopkd") == 0) { 
 391   } else if (strcmp(Cmd
, "loraw") == 0) { 
 393   } else if (strcmp(Cmd
, "hipkd") == 0) { 
 395   } else if (strcmp(Cmd
, "hiraw") == 0) { 
 402 int CmdTune(const char *Cmd
) 
 404     return CmdTuneSamples(Cmd
); 
 407 bool PM3hasSmartcardSlot(void) { 
 408         return (hw_capabilities 
& HAS_SMARTCARD_SLOT
); 
 411 int CmdVersion(const char *Cmd
) 
 414         clearCommandBuffer(); 
 415         UsbCommand c 
= {CMD_VERSION
}; 
 416         UsbCommand resp 
= {0, {0, 0, 0}}; 
 419         if (WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)) { 
 420                 PrintAndLog("Prox/RFID mark3 RFID instrument"); 
 421                 PrintAndLog((char*)resp
.d
.asBytes
); 
 422                 lookupChipID(resp
.arg
[0], resp
.arg
[1]); 
 423                 hw_capabilities 
= resp
.arg
[2]; 
 428 int CmdStatus(const char *Cmd
) 
 430         clearCommandBuffer(); 
 431         UsbCommand c 
= {CMD_STATUS
}; 
 433         if (!WaitForResponseTimeout(CMD_ACK
, &c
, 1900)) { 
 434                 PrintAndLog("Status command failed. USB Speed Test timed out"); 
 440 int CmdPing(const char *Cmd
) 
 442         clearCommandBuffer(); 
 444         UsbCommand c 
= {CMD_PING
}; 
 446         if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) { 
 447                 PrintAndLog("Ping successful"); 
 449                 PrintAndLog("Ping failed"); 
 454 static command_t CommandTable
[] =  
 456         {"help",          CmdHelp
,        1, "This help"}, 
 457         {"detectreader",  CmdDetectReader
,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"}, 
 458         {"fpgaoff",       CmdFPGAOff
,     0, "Set FPGA off"}, 
 459         {"lcd",           CmdLCD
,         0, "<HEX command> <count> -- Send command/data to LCD"}, 
 460         {"lcdreset",      CmdLCDReset
,    0, "Hardware reset LCD"}, 
 461         {"readmem",       CmdReadmem
,     0, "[address] -- Read memory at decimal address from flash"}, 
 462         {"reset",         CmdReset
,       0, "Reset the Proxmark3"}, 
 463         {"setlfdivisor",  CmdSetDivisor
,  0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"}, 
 464         {"setmux",        CmdSetMux
,      0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"}, 
 465         {"tune",          CmdTune
,        0, "['l'|'h'] -- Measure antenna tuning (option 'l' or 'h' to limit to LF or HF)"}, 
 466         {"version",       CmdVersion
,     0, "Show version information about the connected Proxmark"}, 
 467         {"status",        CmdStatus
,      0, "Show runtime status information about the connected Proxmark"}, 
 468         {"ping",          CmdPing
,        0, "Test if the pm3 is responsive"}, 
 469         {NULL
, NULL
, 0, NULL
} 
 472 int CmdHW(const char *Cmd
) 
 474   CmdsParse(CommandTable
, Cmd
); 
 478 int CmdHelp(const char *Cmd
) 
 480   CmdsHelp(CommandTable
);