X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/aacb96d7ed1723663fddd4e2611c22c971442cbd..ac36c57789d2f7aa469aff4a1cc92cda68bc6c15:/client/cmdhflegic.c

diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c
index ab9df487..0262f81c 100644
--- a/client/cmdhflegic.c
+++ b/client/cmdhflegic.c
@@ -38,9 +38,20 @@ int usage_legic_load(void){
 	return 0;
 }
 
+int usage_legic_read(void){	
+	PrintAndLog("Read data from a legic tag.");
+	PrintAndLog("Usage:  hf legic read <offset> <num of bytes>");
+	PrintAndLog("Options :");
+	PrintAndLog("  <offset>        : offset in data array to start download from");
+	PrintAndLog("  <num of bytes>  : number of bytes to download");
+	PrintAndLog("");
+	PrintAndLog(" sample: hf legic read");
+	return 0;
+}
+
 /*
  *  Output BigBuf and deobfuscate LEGIC RF tag data.
- *   This is based on information given in the talk held
+ *  This is based on information given in the talk held
  *  by Henryk Ploetz and Karsten Nohl at 26c3
  */
 int CmdLegicDecode(const char *Cmd) {
@@ -53,11 +64,11 @@ int CmdLegicDecode(const char *Cmd) {
 	int crc = 0;
 	int wrp = 0;
 	int wrc = 0;
-	uint8_t data_buf[1200]; // receiver buffer,  should be 1024..
+	uint8_t data_buf[1024]; // receiver buffer,  should be 1024..
 	char token_type[4];
 
-	// copy data from proxmark into buffer
-	GetFromBigBuf(data_buf, sizeof(data_buf), 0);
+	// download EML memory, where the "legic read" command puts the data.
+	GetEMLFromBigBuf(data_buf, sizeof(data_buf), 0);
 	if ( !WaitForResponseTimeout(CMD_ACK, NULL, 2000)){
 		PrintAndLog("Command execute timeout");
 		return 1;
@@ -132,6 +143,8 @@ int CmdLegicDecode(const char *Cmd) {
 
 	print_hex_break( data_buf, 33, 16);
 	
+	return 0;
+	
 	PrintAndLog("\nADF: User Area");
 	PrintAndLog("------------------------------------------------------");
 	i = 22;  
@@ -236,6 +249,13 @@ int CmdLegicDecode(const char *Cmd) {
 }
 
 int CmdLegicRFRead(const char *Cmd) {
+	
+	// params:
+	// offset in data
+	// number of bytes.
+	char cmdp = param_getchar(Cmd, 0);
+	if ( cmdp == 'H' || cmdp == 'h' ) return usage_legic_read();
+	
 	int byte_count=0, offset=0;
 	sscanf(Cmd, "%i %i", &offset, &byte_count);
 	if(byte_count == 0) byte_count = -1;
@@ -424,13 +444,16 @@ int CmdLegicRfFill(const char *Cmd) {
 int CmdLegicCalcCrc8(const char *Cmd){
 
 	int len =  strlen(Cmd);	
-	if (len & 1 ) return usage_legic_calccrc8(); 
+	if ( len & 1 ) return usage_legic_calccrc8(); 
 	
 	// add 1 for null terminator.
 	uint8_t *data = malloc(len+1);
 	if ( data == NULL ) return 1;
 		
-	if (!param_gethex(Cmd, 0, data, len )) return usage_legic_calccrc8(); 
+	if (param_gethex(Cmd, 0, data, len )) {
+		free(data);
+		return usage_legic_calccrc8();	
+	}
 	
 	uint32_t checksum =  CRC8Legic(data, len/2);	
 	PrintAndLog("Bytes: %s || CRC8: %X", sprint_hex(data, len/2), checksum );