From: Craig Young <cyoung@tripwire.com>
Date: Sat, 25 Jul 2015 18:38:57 +0000 (-0400)
Subject: Merging changes from main repo
X-Git-Tag: v2.3.0~30^2~1
X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/d976c9ddb2b57ff690cbdca033f5423983f60635?ds=inline

Merging changes from main repo
---

diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c
index 510f7bef..a938d5c6 100644
--- a/armsrc/BigBuf.c
+++ b/armsrc/BigBuf.c
@@ -88,6 +88,16 @@ void BigBuf_free_keep_EM(void)
 	}
 }
 
+void BigBuf_print_status(void)
+{
+	Dbprintf("Memory");
+	Dbprintf("  BIGBUF_SIZE.............%d", BIGBUF_SIZE);
+	Dbprintf("  BigBuf_hi  .............%d", BigBuf_hi);
+	Dbprintf("Tracing");
+	Dbprintf("  tracing ................%d", tracing);
+	Dbprintf("  traceLen ...............%d", traceLen);
+}
+
 
 // return the maximum trace length (i.e. the unallocated size of BigBuf)
 uint16_t BigBuf_max_traceLen(void)
diff --git a/armsrc/BigBuf.h b/armsrc/BigBuf.h
index 0e2f1744..05b4180e 100644
--- a/armsrc/BigBuf.h
+++ b/armsrc/BigBuf.h
@@ -28,7 +28,7 @@ extern void BigBuf_Clear(void);
 extern uint8_t *BigBuf_malloc(uint16_t);
 extern void BigBuf_free(void);
 extern void BigBuf_free_keep_EM(void);
-
+extern void BigBuf_print_status(void);
 extern uint16_t BigBuf_get_traceLen(void);
 extern void clear_trace();
 extern void set_tracing(bool enable);
diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c
index 16fed7c5..308dda8c 100644
--- a/armsrc/fpgaloader.c
+++ b/armsrc/fpgaloader.c
@@ -558,3 +558,11 @@ void SetAdcMuxFor(uint32_t whichGpio)
 
 	HIGH(whichGpio);
 }
+
+void Fpga_print_status(void)
+{
+	Dbprintf("Fgpa");
+	if(downloaded_bitstream == FPGA_BITSTREAM_HF) Dbprintf("  mode.............HF");
+	else if(downloaded_bitstream == FPGA_BITSTREAM_LF) Dbprintf("  mode.............LF");
+	else Dbprintf("  mode.............%d", downloaded_bitstream);
+}
diff --git a/armsrc/fpgaloader.h b/armsrc/fpgaloader.h
index 0bad3809..52d6c677 100644
--- a/armsrc/fpgaloader.h
+++ b/armsrc/fpgaloader.h
@@ -17,6 +17,7 @@ void FpgaGatherVersion(int bitstream_version, char *dst, int len);
 void FpgaSetupSsc(void);
 void SetupSpi(int mode);
 bool FpgaSetupSscDma(uint8_t *buf, int len);
+void Fpga_print_status();
 #define FpgaDisableSscDma(void)	AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
 #define FpgaEnableSscDma(void) AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
 void SetAdcMuxFor(uint32_t whichGpio);
diff --git a/armsrc/lfsampling.c b/armsrc/lfsampling.c
index 662ebf24..6e783769 100644
--- a/armsrc/lfsampling.c
+++ b/armsrc/lfsampling.c
@@ -17,7 +17,7 @@ sample_config config = { 1, 8, 1, 95, 0 } ;
 
 void printConfig()
 {
-	Dbprintf("Sampling config: ");
+	Dbprintf("LF Sampling config: ");
 	Dbprintf("  [q] divisor:           %d ", config.divisor);
 	Dbprintf("  [b] bps:               %d ", config.bits_per_sample);
 	Dbprintf("  [d] decimation:        %d ", config.decimation);
diff --git a/armsrc/lfsampling.h b/armsrc/lfsampling.h
index 6c671ec8..7d3925cd 100644
--- a/armsrc/lfsampling.h
+++ b/armsrc/lfsampling.h
@@ -56,4 +56,8 @@ void LFSetupFPGAForADC(int divisor, bool lf_field);
 void setSamplingConfig(sample_config *sc);
 
 sample_config * getSamplingConfig();
+
+void printConfig();
+
+
 #endif // LFSAMPLING_H
diff --git a/armsrc/mifareutil.h b/armsrc/mifareutil.h
index 85a34ef6..7a09ce64 100644
--- a/armsrc/mifareutil.h
+++ b/armsrc/mifareutil.h
@@ -8,6 +8,7 @@
 //-----------------------------------------------------------------------------
 // code for work with mifare cards.
 //-----------------------------------------------------------------------------
+#include "crapto1.h"
 
 #ifndef __MIFAREUTIL_H
 #define __MIFAREUTIL_H
diff --git a/client/cmdhw.c b/client/cmdhw.c
index 2b6f9518..23b6ce21 100644
--- a/client/cmdhw.c
+++ b/client/cmdhw.c
@@ -405,33 +405,64 @@ int CmdTune(const char *Cmd)
 int CmdVersion(const char *Cmd)
 {
 
+	clearCommandBuffer();
 	UsbCommand c = {CMD_VERSION};
-	UsbCommand resp = {0, {0, 0, 0}};
+	static UsbCommand resp = {0, {0, 0, 0}};
 
-	SendCommand(&c);
-	if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+	if (resp.arg[0] == 0 && resp.arg[1] == 0) { // no cached information available
+		SendCommand(&c);
+		if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+			PrintAndLog("Prox/RFID mark3 RFID instrument");
+			PrintAndLog((char*)resp.d.asBytes);
+			lookupChipID(resp.arg[0], resp.arg[1]);
+		}
+	} else {
+		PrintAndLog("[[[ Cached information ]]]\n");
 		PrintAndLog("Prox/RFID mark3 RFID instrument");
 		PrintAndLog((char*)resp.d.asBytes);
 		lookupChipID(resp.arg[0], resp.arg[1]);
+		PrintAndLog("");
 	}
+	return 0;
+}
 
+int CmdStatus(const char *Cmd)
+{
+	UsbCommand c = {CMD_STATUS};
+	SendCommand(&c);
+	return 0;
+}
+
+int CmdPing(const char *Cmd)
+{
+	clearCommandBuffer();
+	UsbCommand resp;
+	UsbCommand c = {CMD_PING};
+	SendCommand(&c);
+	if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+		PrintAndLog("Ping successfull");
+	}else{
+		PrintAndLog("Ping failed");
+	}
 	return 0;
 }
 
 static command_t CommandTable[] = 
 {
-  {"help",          CmdHelp,        1, "This help"},
-  {"detectreader",  CmdDetectReader,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
-  {"fpgaoff",       CmdFPGAOff,     0, "Set FPGA off"},
-  {"lcd",           CmdLCD,         0, "<HEX command> <count> -- Send command/data to LCD"},
-  {"lcdreset",      CmdLCDReset,    0, "Hardware reset LCD"},
-  {"readmem",       CmdReadmem,     0, "[address] -- Read memory at decimal address from flash"},
-  {"reset",         CmdReset,       0, "Reset the Proxmark3"},
-  {"setlfdivisor",  CmdSetDivisor,  0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
-  {"setmux",        CmdSetMux,      0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
-  {"tune",          CmdTune,        0, "Measure antenna tuning"},
-  {"version",       CmdVersion,     0, "Show version information about the connected Proxmark"},
-  {NULL, NULL, 0, NULL}
+	{"help",          CmdHelp,        1, "This help"},
+	{"detectreader",  CmdDetectReader,0, "['l'|'h'] -- Detect external reader field (option 'l' or 'h' to limit to LF or HF)"},
+	{"fpgaoff",       CmdFPGAOff,     0, "Set FPGA off"},
+	{"lcd",           CmdLCD,         0, "<HEX command> <count> -- Send command/data to LCD"},
+	{"lcdreset",      CmdLCDReset,    0, "Hardware reset LCD"},
+	{"readmem",       CmdReadmem,     0, "[address] -- Read memory at decimal address from flash"},
+	{"reset",         CmdReset,       0, "Reset the Proxmark3"},
+	{"setlfdivisor",  CmdSetDivisor,  0, "<19 - 255> -- Drive LF antenna at 12Mhz/(divisor+1)"},
+	{"setmux",        CmdSetMux,      0, "<loraw|hiraw|lopkd|hipkd> -- Set the ADC mux to a specific value"},
+	{"tune",          CmdTune,        0, "Measure antenna tuning"},
+	{"version",       CmdVersion,     0, "Show version information about the connected Proxmark"},
+	{"status",        CmdStatus,      0, "Show runtime status information about the connected Proxmark"},
+	{"ping",          CmdPing,        0, "Test if the pm3 is responsive"},
+	{NULL, NULL, 0, NULL}
 };
 
 int CmdHW(const char *Cmd)
diff --git a/client/lualibs/commands.lua b/client/lualibs/commands.lua
index 127508e6..64f16e44 100644
--- a/client/lualibs/commands.lua
+++ b/client/lualibs/commands.lua
@@ -20,7 +20,8 @@ local _commands = {
 	CMD_BUFF_CLEAR =                                                     0x0105,
 	CMD_READ_MEM =                                                       0x0106,
 	CMD_VERSION =                                                        0x0107,
-
+	CMD_STATUS =                                                         0x0108,
+	CMD_PING =                                                           0x0109,
 	--// For low-frequency tags
 	CMD_READ_TI_TYPE =                                                   0x0202,
 	CMD_WRITE_TI_TYPE =                                                  0x0203,
diff --git a/include/usb_cmd.h b/include/usb_cmd.h
index e45bf35e..f443e970 100644
--- a/include/usb_cmd.h
+++ b/include/usb_cmd.h
@@ -60,6 +60,8 @@ typedef struct{
 #define CMD_BUFF_CLEAR                                                    0x0105
 #define CMD_READ_MEM                                                      0x0106
 #define CMD_VERSION                                                       0x0107
+#define CMD_STATUS														  0x0108
+#define CMD_PING														  0x0109
 
 // For low-frequency tags
 #define CMD_READ_TI_TYPE                                                  0x0202