From 25f358955b917a2fc028ff413c29499dda81eee1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 3 Aug 2019 22:14:04 +0200 Subject: [PATCH] make hf search robust to various HF configurations --- armsrc/appmain.c | 6 ++++ armsrc/iso14443a.c | 20 +++++++------- armsrc/iso14443a.h | 2 +- armsrc/thinfilm.c | 2 +- client/cmdhf.c | 69 +++++++++++++++++++++++++++++----------------- client/util.h | 2 +- include/pm3_cmd.h | 1 + 7 files changed, 63 insertions(+), 39 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 5d2f2146b..5c2788b53 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1090,6 +1090,12 @@ static void PacketReceived(PacketCommandNG *packet) { } #endif +// always available + case CMD_HF_DROPFIELD: { + hf_field_off(); + break; + } + #ifdef WITH_ISO14443a case CMD_HF_ISO14443A_SNIFF: { SniffIso14443a(packet->data.asBytes[0]); diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 554fe57fa..e5bf6487a 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -14,7 +14,7 @@ #define MAX_ISO14A_TIMEOUT 524288 static uint32_t iso14a_timeout; // if iso14443a not active - transmit/receive dont try to execute -static bool iso14443a_active = false; +static bool hf_field_active = false; uint8_t colpos = 0; int rsamples = 0; @@ -1629,7 +1629,7 @@ void PrepareDelayedTransfer(uint16_t delay) { //------------------------------------------------------------------------------------- static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing) { - if (!iso14443a_active) + if (!hf_field_active) return; FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD); @@ -2014,7 +2014,7 @@ bool EmLogTrace(uint8_t *reader_data, uint16_t reader_len, uint32_t reader_Start //----------------------------------------------------------------------------- bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint8_t *received_len) { - if (!iso14443a_active) + if (!hf_field_active) return false; // Set FPGA mode to "reader listen mode", no modulation (listen @@ -2063,7 +2063,7 @@ bool GetIso14443aAnswerFromTag_Thinfilm(uint8_t *receivedResponse, uint8_t *rec static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receivedResponsePar, uint16_t offset) { uint32_t c = 0; - if (!iso14443a_active) + if (!hf_field_active) return false; // Set FPGA mode to "reader listen mode", no modulation (listen @@ -2504,14 +2504,14 @@ void iso14443a_setup(uint8_t fpga_minor_mode) { NextTransferTime = 2 * DELAY_ARM2AIR_AS_READER; iso14a_set_timeout(1060); // 106 * 10ms default - iso14443a_active = true; + hf_field_active = true; } -void iso14443a_off(void) { +void hf_field_off(void) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); - iso14443a_active = false; + hf_field_active = false; } /* Peter Fillmore 2015 @@ -2716,7 +2716,7 @@ void ReaderIso14443a(PacketCommandNG *c) { return; OUT: - iso14443a_off(); + hf_field_off(); set_tracing(false); } @@ -3011,7 +3011,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) { reply_mix(CMD_ACK, isOK, 0, 0, buf, sizeof(buf)); - iso14443a_off(); + hf_field_off(); set_tracing(false); } @@ -3250,6 +3250,6 @@ void DetectNACKbug(void) { //reply_mix(CMD_ACK, isOK, num_nacks, i, 0, 0); BigBuf_free(); - iso14443a_off(); + hf_field_off(); set_tracing(false); } diff --git a/armsrc/iso14443a.h b/armsrc/iso14443a.h index fab0dbdeb..323fb8a97 100644 --- a/armsrc/iso14443a.h +++ b/armsrc/iso14443a.h @@ -132,7 +132,7 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats); int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades); void iso14a_set_trigger(bool enable); -void iso14443a_off(void); +void hf_field_off(void); int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen); int EmSend4bit(uint8_t resp); diff --git a/armsrc/thinfilm.c b/armsrc/thinfilm.c index 93d46e8a1..9230642e0 100644 --- a/armsrc/thinfilm.c +++ b/armsrc/thinfilm.c @@ -32,7 +32,7 @@ void ReadThinFilm(void) { bool status = GetIso14443aAnswerFromTag_Thinfilm(buf, &len); reply_ng(CMD_HF_THINFILM_READ, status ? PM3_SUCCESS : PM3_ENODATA, buf, len); - iso14443a_off(); + hf_field_off(); set_tracing(false); } diff --git a/client/cmdhf.c b/client/cmdhf.c index 2ef54773d..6e1dcccdb 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -54,42 +54,59 @@ int CmdHFSearch(const char *Cmd) { PrintAndLogEx(INFO, "Checking for known tags...\n"); - if (infoThinFilm(false) == PM3_SUCCESS) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n"); - return 1; + if (IfPm3NfcBarcode()) { + if (infoThinFilm(false) == PM3_SUCCESS) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n"); + return 1; + } } - - if (infoHF14A(false, false) > 0) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-A tag") " found\n"); - return 1; + if (IfPm3Iso14443a()) { + if (infoHF14A(false, false) > 0) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-A tag") " found\n"); + return 1; + } } - if (readHF15Uid(false) == 1) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO15693 tag") " found\n"); - return 1; + if (IfPm3Iso15693()) { + if (readHF15Uid(false) == 1) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO15693 tag") " found\n"); + DropField(); + return 1; + } + DropField(); } - if (readLegicUid(false) == 0) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LEGIC tag") " found\n"); - return 1; + if (IfPm3Legicrf()) { + if (readLegicUid(false) == 0) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LEGIC tag") " found\n"); + return 1; + } } - if (readTopazUid() == 0) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n"); - return 1; + if (IfPm3Iso14443a()) { + if (readTopazUid() == 0) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n"); + return 1; + } } // 14b and iclass is the longest test (put last) - if (readHF14B(false) == 1) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-B tag") " found\n"); - return 1; + if (IfPm3Iso14443a()) { + if (readHF14B(false) == 1) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO14443-B tag") " found\n"); + return 1; + } } - if (readIclass(false, false) == 1) { - PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("iClass tag / PicoPass tag") " found\n"); - return 1; + if (IfPm3Iclass()) { + if (readIclass(false, false) == 1) { + PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("iClass tag / PicoPass tag") " found\n"); + return 1; + } } /* - ans = CmdHFFelicaReader("s"); - if (ans) { - PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n"); - return ans; + if (IfPm3Felica()) { + ans = CmdHFFelicaReader("s"); + if (ans) { + PrintAndLogEx(NORMAL, "\nValid " _GREEN_("ISO18092 / FeliCa tag") " found\n"); + return ans; + } } */ diff --git a/client/util.h b/client/util.h index f1d55b140..8861045d8 100644 --- a/client/util.h +++ b/client/util.h @@ -33,7 +33,7 @@ #ifndef DropField #define DropField() { \ - clearCommandBuffer(); SendCommandMIX(CMD_HF_ISO14443A_READER, 0, 0, 0, NULL, 0); \ + clearCommandBuffer(); SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); \ } #endif diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 267ac749a..f3231fe5a 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -425,6 +425,7 @@ typedef struct { #define CMD_MEASURE_ANTENNA_TUNING 0x0400 #define CMD_MEASURE_ANTENNA_TUNING_HF 0x0401 #define CMD_LISTEN_READER_FIELD 0x0420 +#define CMD_HF_DROPFIELD 0x0430 // For direct FPGA control #define CMD_FPGA_MAJOR_MODE_OFF 0x0500