From: marshmellow42 <marshmellowrf@gmail.com>
Date: Tue, 12 May 2015 04:19:44 +0000 (-0400)
Subject: hf search - prelim - re-use hf mfu GetTagType...
X-Git-Tag: v2.1.0~12^2~28
X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/8ceb6b03e5caee0cc7292894bfa25fa4a3f85c4c?hp=2be768af57ffa83d416f7728fbf790fe9e405c54

hf search - prelim - re-use hf mfu GetTagType...

in hf 14a reader to identify UL(+)

still a work in progress.
---

diff --git a/client/cmdhf.c b/client/cmdhf.c
index 020ea94c..524d9c2e 100644
--- a/client/cmdhf.c
+++ b/client/cmdhf.c
@@ -544,6 +544,21 @@ int CmdHFList(const char *Cmd)
 	return 0;
 }
 
+int CmdHFSearch(const char *Cmd){
+	int ans = 0;
+	ans = CmdHF14AReader(Cmd);
+	if (ans > 0) return ans;
+
+	ans = CmdHF15Reader(Cmd);
+	//if (ans > 0) return ans;	
+
+	ans = CmdHF14BRead(Cmd);
+	//if (ans > 0) return ans;
+
+	ans = CmdHFiClassReader(Cmd);
+	//if (ans > 0) return ans;
+	return 0;
+}
 
 static command_t CommandTable[] = 
 {
@@ -554,10 +569,11 @@ static command_t CommandTable[] =
   {"epa",         CmdHFEPA,         1, "{ German Identification Card... }"},
   {"legic",       CmdHFLegic,       0, "{ LEGIC RFIDs... }"},
   {"iclass",      CmdHFiClass,      1, "{ ICLASS RFIDs... }"},
-  {"mf",      		CmdHFMF,		1, "{ MIFARE RFIDs... }"},
-  {"mfu",			CmdHFMFUltra,		1, "{ MIFARE Ultralight RFIDs... }"},
+  {"mf",          CmdHFMF,          1, "{ MIFARE RFIDs... }"},
+  {"mfu",         CmdHFMFUltra,     1, "{ MIFARE Ultralight RFIDs... }"},
   {"tune",        CmdHFTune,        0, "Continuously measure HF antenna tuning"},
-  {"list",       CmdHFList,         1, "List protocol data in trace buffer"},
+  {"list",        CmdHFList,        1, "List protocol data in trace buffer"},
+  {"search",      CmdHFSearch,      1, "Search for known HF tags"},
 	{NULL, NULL, 0, NULL}
 };
 
diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c
index d4285eea..d1f8b363 100644
--- a/client/cmdhf14a.c
+++ b/client/cmdhf14a.c
@@ -23,6 +23,7 @@
 #include "common.h"
 #include "cmdmain.h"
 #include "mifare.h"
+#include "cmdhfmfu.h"
 
 static int CmdHelp(const char *Cmd);
 static void waitCmd(uint8_t iLen);
@@ -169,6 +170,42 @@ int CmdHF14AReader(const char *Cmd)
 
 	switch (card.sak) {
 		case 0x00: 
+
+			//***************************************test****************
+			// disconnect
+			c.arg[0] = 0;
+			c.arg[1] = 0;
+			c.arg[2] = 0;
+			SendCommand(&c);
+			
+			uint16_t tagT = GetHF14AMfU_Type();
+			ul_print_type(tagT, 0);
+
+			//reconnect for further tests
+			c.arg[0] = ISO14A_CONNECT | ISO14A_NO_DISCONNECT;
+			c.arg[1] = 0;
+			c.arg[2] = 0;
+
+			SendCommand(&c);
+
+			UsbCommand resp;
+			WaitForResponse(CMD_ACK,&resp);
+			
+			memcpy(&card, (iso14a_card_select_t *)resp.d.asBytes, sizeof(iso14a_card_select_t));
+
+			select_status = resp.arg[0];		// 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS
+			
+			if(select_status == 0) {
+				//PrintAndLog("iso14443a card select failed");
+				// disconnect
+				c.arg[0] = 0;
+				c.arg[1] = 0;
+				c.arg[2] = 0;
+				SendCommand(&c);
+				return 0;
+			}
+
+			/*  orig
 			// check if the tag answers to GETVERSION (0x60)
 			c.arg[0] = ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT;
 			c.arg[1] = 1;
@@ -187,7 +224,7 @@ int CmdHF14AReader(const char *Cmd)
 				case 0x01:PrintAndLog("TYPE : NXP MIFARE Ultralight C");break;
 				case 0x00:PrintAndLog("TYPE : NXP MIFARE Ultralight");break;	
 			}
-
+			*/
 			break;
 		case 0x01: PrintAndLog("TYPE : NXP TNP3xxx Activision Game Appliance"); break;
 		case 0x04: PrintAndLog("TYPE : NXP MIFARE (various !DESFire !DESFire EV1)"); break;
diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c
index fec7a85e..884ed3ff 100644
--- a/client/cmdhfmfu.c
+++ b/client/cmdhfmfu.c
@@ -23,26 +23,6 @@
 #define MAX_NTAG_215      0x86
 #define MAX_NTAG_216      0xe6
 
-typedef enum TAGTYPE_UL {
-	UNKNOWN       = 0x0000,
-	UL            = 0x0001,
-	UL_C          = 0x0002,
-	UL_EV1_48     = 0x0004,
-	UL_EV1_128    = 0x0008,
-	NTAG          = 0x0010,
-	NTAG_213      = 0x0020,
-	NTAG_215      = 0x0040,
-	NTAG_216      = 0x0080,
-	MY_D          = 0x0100,
-	MY_D_NFC      = 0x0200,
-	MY_D_MOVE     = 0x0400,
-	MY_D_MOVE_NFC = 0x0800,
-	MAGIC         = 0x1000,
-	UL_MAGIC      = UL | MAGIC,
-	UL_C_MAGIC    = UL_C | MAGIC,
-	UL_ERROR      = 0xFFFF,
-} TagTypeUL_t;
-
 #define KEYS_3DES_COUNT 7
 uint8_t default_3des_keys[KEYS_3DES_COUNT][16] = {
 		{ 0x42,0x52,0x45,0x41,0x4b,0x4d,0x45,0x49,0x46,0x59,0x4f,0x55,0x43,0x41,0x4e,0x21 },// 3des std key
@@ -314,31 +294,35 @@ static int ntag_print_CC(uint8_t *data) {
 	return 0;
 }
 
-static int ul_print_type(uint16_t tagtype){
+int ul_print_type(uint16_t tagtype, uint8_t spaces){
+	char spc[11] = "          ";
+	spc[10]=0x00;
+	char *spacer = spc + (10-spaces);
+
 	if ( tagtype & UL )	
-		PrintAndLog("      TYPE : MIFARE Ultralight (MF0ICU1) %s [%x]", (tagtype & MAGIC)?"<magic>":"", tagtype);
+		PrintAndLog("%sTYPE : MIFARE Ultralight (MF0ICU1) %s [%x]", spacer, (tagtype & MAGIC)?"<magic>":"", tagtype);
 	else if ( tagtype & UL_C)
-		PrintAndLog("      TYPE : MIFARE Ultralight C (MF0ULC) %s [%x]", (tagtype & MAGIC)?"<magic>":"", tagtype );
+		PrintAndLog("%sTYPE : MIFARE Ultralight C (MF0ULC) %s [%x]", spacer, (tagtype & MAGIC)?"<magic>":"", tagtype );
 	else if ( tagtype & UL_EV1_48)
-		PrintAndLog("      TYPE : MIFARE Ultralight EV1 48bytes (MF0UL1101)"); 
+		PrintAndLog("%sTYPE : MIFARE Ultralight EV1 48bytes (MF0UL1101)", spacer); 
 	else if ( tagtype & UL_EV1_128)
-		PrintAndLog("      TYPE : MIFARE Ultralight EV1 128bytes (MF0UL2101)");
+		PrintAndLog("%sTYPE : MIFARE Ultralight EV1 128bytes (MF0UL2101)", spacer);
 	else if ( tagtype & NTAG_213 )
-		PrintAndLog("      TYPE : MIFARE NTAG 213 144bytes (NT2H1311G0DU)");
+		PrintAndLog("%sTYPE : MIFARE NTAG 213 144bytes (NT2H1311G0DU)", spacer);
 	else if ( tagtype & NTAG_215 )
-		PrintAndLog("      TYPE : MIFARE NTAG 215 504bytes (NT2H1511G0DU)");
+		PrintAndLog("%sTYPE : MIFARE NTAG 215 504bytes (NT2H1511G0DU)", spacer);
 	else if ( tagtype & NTAG_216 )
-		PrintAndLog("      TYPE : MIFARE NTAG 216 888bytes (NT2H1611G0DU)");
+		PrintAndLog("%sTYPE : MIFARE NTAG 216 888bytes (NT2H1611G0DU)", spacer);
 	else if ( tagtype & MY_D )
-		PrintAndLog("      TYPE : INFINEON my-d\x99");
+		PrintAndLog("%sTYPE : INFINEON my-d\x99", spacer);
 	else if ( tagtype & MY_D_NFC )
-		PrintAndLog("      TYPE : INFINEON my-d\x99 NFC");
+		PrintAndLog("%sTYPE : INFINEON my-d\x99 NFC", spacer);
 	else if ( tagtype & MY_D_MOVE )
-		PrintAndLog("      TYPE : INFINEON my-d\x99 move");
+		PrintAndLog("%sTYPE : INFINEON my-d\x99 move", spacer);
 	else if ( tagtype & MY_D_MOVE_NFC )
-		PrintAndLog("      TYPE : INFINEON my-d\x99 move NFC");
+		PrintAndLog("%sTYPE : INFINEON my-d\x99 move NFC", spacer);
 	else
-		PrintAndLog("      TYPE : Unknown %04x",tagtype);
+		PrintAndLog("%sTYPE : Unknown %04x", spacer, tagtype);
 	return 0;
 }
 
@@ -579,7 +563,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
 
 	PrintAndLog("\n--- Tag Information ---------");
 	PrintAndLog("-------------------------------------------------------------");
-	ul_print_type(tagtype);
+	ul_print_type(tagtype, 6);
 
 	status = ul_select(&card);
 	if ( status < 1 ){
diff --git a/client/cmdhfmfu.h b/client/cmdhfmfu.h
index 8e96775c..23f97cac 100644
--- a/client/cmdhfmfu.h
+++ b/client/cmdhfmfu.h
@@ -20,9 +20,31 @@ void rol (uint8_t *data, const size_t len);
 uint8_t requestAuthentication( uint8_t *nonce);
 int try3DesAuthentication( uint8_t *key);
 uint16_t GetHF14AMfU_Type(void);
+int ul_print_type(uint16_t tagtype, uint8_t spacer);
 
 int usage_hf_mfu_dump(void);
 
 int CmdHFMFUltra(const char *Cmd);
 int CmdHF14AMfUInfo(const char *Cmd);
+
+typedef enum TAGTYPE_UL {
+	UNKNOWN       = 0x0000,
+	UL            = 0x0001,
+	UL_C          = 0x0002,
+	UL_EV1_48     = 0x0004,
+	UL_EV1_128    = 0x0008,
+	NTAG          = 0x0010,
+	NTAG_213      = 0x0020,
+	NTAG_215      = 0x0040,
+	NTAG_216      = 0x0080,
+	MY_D          = 0x0100,
+	MY_D_NFC      = 0x0200,
+	MY_D_MOVE     = 0x0400,
+	MY_D_MOVE_NFC = 0x0800,
+	MAGIC         = 0x1000,
+	UL_MAGIC      = UL | MAGIC,
+	UL_C_MAGIC    = UL_C | MAGIC,
+	UL_ERROR      = 0xFFFF,
+} TagTypeUL_t;
+
 #endif