From 50c6a9223d9b0932c71488f4692fceccd07ce9cb Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Mon, 6 Apr 2020 13:59:01 +0200 Subject: [PATCH 1/5] Add NTAG handling, fix TNP3xxx, remove ISO 14443-B card uids --- client/cmdhf14a.c | 87 ++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index f737ff485..eda2d3a3f 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -1251,84 +1251,89 @@ static void printTag(char *tag) { typedef enum { - mtNone = 0, - mtClassic = 1, - mtMini = 2, - mtDESFire = 4, - mtPlus = 8, - mtUltralight = 16, - mtOther = 32 -} nxp_mifare_type; + MTNONE = 0, + MTCLASSIC = 1, + MTMINI = 2, + MTDESFIRE = 4, + MTPLUS = 8, + MTULTRALIGHT = 16, + MTOTHER = 32 +} nxp_mifare_type_t; // According to NXP AN10833 Rev 3.6 MIFARE Type Identification, Table 6 int detect_nxp_card(uint8_t sak, uint16_t atqa) { - int type = mtNone; + int type = MTNONE; if (sak == 0x00) { + printTag("NTAG 21x / NTAG 21x TT / NTAG I2C plus"); printTag("MIFARE Ultralight C / Ultralight CL2"); - type = mtUltralight; + type = MTULTRALIGHT; } if (sak == 0x01) { printTag("TNP3xxx (Activision Game Appliance)"); - type = mtOther; + type = MTCLASSIC; } if ((sak & 0x04) == 0x04) { - printTag("Any MIFARE CL1"); - type |= mtDESFire; + printTag("Any MIFARE CL1 / NTAG424DNA"); + type |= MTDESFIRE; } if ((sak & 0x08) == 0x08) { printTag("MIFARE Classic 1K / Classic 1K CL2"); printTag("MIFARE Plus 2K / Plus EV1 2K"); printTag("MIFARE Plus CL2 2K / Plus CL2 EV1 2K"); - type |= mtClassic; - type |= mtPlus; + type |= MTCLASSIC; + type |= MTPLUS; } if ((sak & 0x09) == 0x09) { printTag("MIFARE Mini 0.3K / Mini CL2 0.3K"); - type |= mtMini; + type |= MTMINI; } if ((sak & 0x10) == 0x10) { printTag("MIFARE Plus 2K / Plus CL2 2K"); - type |= mtPlus; + type |= MTPLUS; } if ((sak & 0x11) == 0x11) { printTag("MIFARE Plus 4K / Plus CL2 4K"); - type |= mtPlus; + type |= MTPLUS; } if ((sak & 0x18) == 0x18) { if (atqa == 0x0042) { printTag("MIFARE Plus 4K / Plus EV1 4K"); printTag("MIFARE Plus CL2 4K / Plus CL2 EV1 4K"); - type |= mtPlus; + type |= MTPLUS; } else { printTag("MIFARE Classic 4K / Classic 4K CL2"); - type |= mtClassic; + type |= MTCLASSIC; } } if ((sak & 0x20) == 0x20) { if (atqa == 0x0344) { printTag("MIFARE DESFire EV1 2K/4K/8K / DESFire EV1 CL2 2K/4K/8K"); - type |= mtDESFire; + printTag("MIFARE NTAG424DNA"); + type |= MTDESFIRE; + } else if (atqa == 0x0304) { + printTag("MIFARE NTAG424DNA (Random ID feature)"); + type |= MTDESFIRE; } else { printTag("MIFARE Plus 2K / Plus EV1 2K"); printTag("MIFARE Plus 4K / Plus EV1 4K"); printTag("MIFARE Plus CL2 2K / Plus CL2 EV1 4K"); printTag("MIFARE Plus CL2 4K / Plus CL2 EV1 4K"); - type |= mtPlus; + type |= MTPLUS; } } if ((sak & 0x24) == 0x24) { if (atqa == 0x0344) { printTag("MIFARE DESFire CL1 / DESFire EV1 CL1"); - type |= mtDESFire; + type |= MTDESFIRE; } } if ((sak & 0x28) == 0x28) { if (atqa == 0x0344) { printTag("MIFARE DESFire CL1 / DESFire EV1 CL1"); - type |= mtDESFire; + type |= MTDESFIRE; } } return type; @@ -1342,16 +1347,6 @@ typedef struct { const uidname uidmap[] = { // UID0, UID1, TEXT - {0x02, 0x00, "SR176"}, - {0x02, 0x03, "SRIX4K"}, - {0x02, 0x0C, "SRT512"}, - {0x02, 0x0F, "SRI2K"}, - {0x02, 0x1B, "25TB512-AC"}, - {0x02, 0x3D, "SRIX4K"}, - {0x02, 0x3F, "25TB02K"}, - {0x02, 0x4D, "SRIX512"}, - {0x02, 0x6D, "SRI512"}, - {0x02, 0x7D, "SRI4K"}, {0x02, 0x84, "M24SR64-Y"}, {0x02, 0xA3, "25TA02KB-P"}, {0x02, 0xC4, "25TA64K"}, @@ -1422,22 +1417,22 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { bool isMifareDESFire = false; bool isMifarePlus = false; bool isMifareUltralight = false; - int nxptype = mtNone; + int nxptype = MTNONE; // Double & triple sized UID, can be mapped to a manufacturer. if (card.uidlen <= 4) { nxptype = detect_nxp_card(card.sak, ((card.atqa[1] << 8) + card.atqa[0])); - if ((nxptype & mtClassic) == mtClassic) isMifareClassic = true; + if ((nxptype & MTCLASSIC) == MTCLASSIC) isMifareClassic = true; else isMifareClassic = false; - if ((nxptype & mtDESFire) == mtDESFire) { + if ((nxptype & MTDESFIRE) == MTDESFIRE) { isMifareDESFire = true; } else { isMifareDESFire = false; } - if ((nxptype & mtPlus) == mtPlus) isMifarePlus = true; + if ((nxptype & MTPLUS) == MTPLUS) isMifarePlus = true; else isMifarePlus = false; - if ((nxptype & mtUltralight) == mtUltralight) isMifareUltralight = true; + if ((nxptype & MTULTRALIGHT) == MTULTRALIGHT) isMifareUltralight = true; else isMifareUltralight = false; - if ((nxptype & mtOther) == mtOther) isMifareClassic = true; + if ((nxptype & MTOTHER) == MTOTHER) isMifareClassic = true; } if (card.uidlen > 4) { PrintAndLogEx(SUCCESS, "MANUFACTURER: " _YELLOW_("%s"), getTagInfo(card.uid[0])); @@ -1446,18 +1441,18 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { switch (card.uid[0]) { case 0x04: // NXP nxptype = detect_nxp_card(card.sak, ((card.atqa[1] << 8) + card.atqa[0])); - if ((nxptype & mtClassic) == mtClassic) isMifareClassic = true; + if ((nxptype & MTCLASSIC) == MTCLASSIC) isMifareClassic = true; else isMifareClassic = false; - if ((nxptype & mtDESFire) == mtDESFire) { + if ((nxptype & MTDESFIRE) == MTDESFIRE) { isMifareDESFire = true; } else { isMifareDESFire = false; } - if ((nxptype & mtPlus) == mtPlus) isMifarePlus = true; + if ((nxptype & MTPLUS) == MTPLUS) isMifarePlus = true; else isMifarePlus = false; - if ((nxptype & mtUltralight) == mtUltralight) isMifareUltralight = true; + if ((nxptype & MTULTRALIGHT) == MTULTRALIGHT) isMifareUltralight = true; else isMifareUltralight = false; - if ((nxptype & mtOther) == mtOther) isMifareClassic = true; + if ((nxptype & MTOTHER) == MTOTHER) isMifareClassic = true; break; case 0x05: // Infineon if ((card.uid[1] & 0xF0) == 0x10) { @@ -1765,7 +1760,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mfdes info`")); } - if (((card.sak & 0x08) == 0x08) || ((card.sak & 0x18) == 0x18)) { + if (isMifareClassic || isMifareUltralight) { detect_classic_magic(); if (isMifareClassic) { From 27ed590d73d9cd13a15709a57176b8b0855a5b71 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Mon, 6 Apr 2020 14:30:21 +0200 Subject: [PATCH 2/5] Add DropField() when errors happen --- client/cmdhf14a.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index eda2d3a3f..76f988619 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -246,17 +246,20 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) { if (select_status == 0) { PrintAndLogEx(ERR, "E->iso14443a card select failed"); + DropField(); return 1; } if (select_status == 2) { PrintAndLogEx(ERR, "E->Card doesn't support iso14443-4 mode"); + DropField(); return 1; } if (select_status == 3) { PrintAndLogEx(INFO, "E->Card doesn't support standard iso14443-3 anticollision"); PrintAndLogEx(SUCCESS, "\tATQA : %02x %02x", card->atqa[1], card->atqa[0]); + DropField(); return 1; } @@ -265,6 +268,7 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) { PrintAndLogEx(SUCCESS, " SAK: %02x [%" PRIu64 "]", card->sak, resp.oldarg[0]); if (card->ats_len < 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes PrintAndLogEx(INFO, "E-> Error ATS length(%d) : %s", card->ats_len, sprint_hex(card->ats, card->ats_len)); + DropField(); return 1; } @@ -416,6 +420,7 @@ static int CmdHF14ACUIDs(const char *Cmd) { // check if command failed if (resp.oldarg[0] == 0) { PrintAndLogEx(WARNING, "card select failed."); + DropField(); } else { char uid_string[20]; for (uint16_t m = 0; m < card->uidlen; m++) { @@ -563,17 +568,20 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!silentMode) PrintAndLogEx(ERR, "Proxmark3 connection timeout."); + DropField(); return 1; } // check result if (resp.oldarg[0] == 0) { if (!silentMode) PrintAndLogEx(ERR, "No card in field."); + DropField(); return 1; } if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) { if (!silentMode) PrintAndLogEx(ERR, "Card not in iso14443-4. res=%" PRId64 ".", resp.oldarg[0]); + DropField(); return 1; } @@ -583,11 +591,13 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav SendCommandOLD(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, 2); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!silentMode) PrintAndLogEx(ERR, "Proxmark3 connection timeout."); + DropField(); return 1; } if (resp.oldarg[0] == 0) { // ats_len if (!silentMode) PrintAndLogEx(ERR, "Can't get ATS."); + DropField(); return 1; } } @@ -610,6 +620,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav if (!iLen) { if (!silentMode) PrintAndLogEx(ERR, "No card response."); + DropField(); return 1; } @@ -619,11 +630,13 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav if (maxdataoutlen && *dataoutlen > maxdataoutlen) { if (!silentMode) PrintAndLogEx(ERR, "Buffer too small(%d). Needs %d bytes", *dataoutlen, maxdataoutlen); + DropField(); return 2; } if (recv[0] != data[0]) { if (!silentMode) PrintAndLogEx(ERR, "iso14443-4 framing error. Card send %2x must be %2x", dataout[0], data[0]); + DropField(); return 2; } @@ -632,11 +645,13 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav // CRC Check if (iLen == -1) { if (!silentMode) PrintAndLogEx(ERR, "ISO 14443A CRC error."); + DropField(); return 3; } } else { if (!silentMode) PrintAndLogEx(ERR, "Reply timeout."); + DropField(); return 4; } @@ -657,17 +672,20 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(ERR, "Proxmark3 connection timeout."); + DropField(); return 1; } // check result if (resp.oldarg[0] == 0) { PrintAndLogEx(ERR, "No card in field."); + DropField(); return 1; } if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) { PrintAndLogEx(ERR, "Card not in iso14443-4. res=%" PRId64 ".", resp.oldarg[0]); + DropField(); return 1; } @@ -677,11 +695,13 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { SendCommandOLD(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, sizeof(rats), 0, rats, sizeof(rats)); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(ERR, "Proxmark3 connection timeout."); + DropField(); return 1; } if (resp.oldarg[0] == 0) { // ats_len PrintAndLogEx(ERR, "Can't get ATS."); + DropField(); return 1; } @@ -759,18 +779,21 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool if (!iLen) { PrintAndLogEx(ERR, "APDU: No APDU response."); + DropField(); return 1; } // check apdu length if (iLen < 2 && iLen >= 0) { PrintAndLogEx(ERR, "APDU: Small APDU response. Len=%d", iLen); + DropField(); return 2; } // check block TODO if (iLen == -2) { PrintAndLogEx(ERR, "APDU: Block type mismatch."); + DropField(); return 2; } @@ -784,10 +807,12 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool // CRC Check if (iLen == -1) { PrintAndLogEx(ERR, "APDU: ISO 14443A CRC error."); + DropField(); return 3; } } else { PrintAndLogEx(ERR, "APDU: Reply timeout."); + DropField(); return 4; } @@ -1149,12 +1174,15 @@ static int waitCmd(uint8_t iSelect) { PrintAndLogEx(NORMAL, "received %i bytes", len); } - if (!len) + if (!len) { + DropField(); return 1; + } PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.data.asBytes, len)); } else { PrintAndLogEx(WARNING, "timeout while waiting for reply."); + DropField(); return 3; } return 0; From c1ba18db8d6e866ca15740513e0b0de6374bcc7d Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Mon, 6 Apr 2020 14:37:01 +0200 Subject: [PATCH 3/5] Update Changelog.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 946b7c541..bd11728cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Improved `hf 14a info` - card detection handling (@bkerler) - Updated helptext layout in all luascripts (@iceman1001) - - Change `hf mfdes info` - output and logging (@brkeler) + - Change `hf mfdes info` - output and logging (@bkerler) - Updated texts in legic commands (@ikarus23) - Fix timing bug inside 40x5 (@mwalker33) - Refactored all Hitag2 attacks (@doegox) From 0bcc2a90256059c45aba9b94bf55b2b24d3da7dc Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Mon, 6 Apr 2020 15:14:16 +0200 Subject: [PATCH 4/5] Revert DropField commit --- client/cmdhf14a.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 76f988619..eda2d3a3f 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -246,20 +246,17 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) { if (select_status == 0) { PrintAndLogEx(ERR, "E->iso14443a card select failed"); - DropField(); return 1; } if (select_status == 2) { PrintAndLogEx(ERR, "E->Card doesn't support iso14443-4 mode"); - DropField(); return 1; } if (select_status == 3) { PrintAndLogEx(INFO, "E->Card doesn't support standard iso14443-3 anticollision"); PrintAndLogEx(SUCCESS, "\tATQA : %02x %02x", card->atqa[1], card->atqa[0]); - DropField(); return 1; } @@ -268,7 +265,6 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card) { PrintAndLogEx(SUCCESS, " SAK: %02x [%" PRIu64 "]", card->sak, resp.oldarg[0]); if (card->ats_len < 3) { // a valid ATS consists of at least the length byte (TL) and 2 CRC bytes PrintAndLogEx(INFO, "E-> Error ATS length(%d) : %s", card->ats_len, sprint_hex(card->ats, card->ats_len)); - DropField(); return 1; } @@ -420,7 +416,6 @@ static int CmdHF14ACUIDs(const char *Cmd) { // check if command failed if (resp.oldarg[0] == 0) { PrintAndLogEx(WARNING, "card select failed."); - DropField(); } else { char uid_string[20]; for (uint16_t m = 0; m < card->uidlen; m++) { @@ -568,20 +563,17 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!silentMode) PrintAndLogEx(ERR, "Proxmark3 connection timeout."); - DropField(); return 1; } // check result if (resp.oldarg[0] == 0) { if (!silentMode) PrintAndLogEx(ERR, "No card in field."); - DropField(); return 1; } if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) { if (!silentMode) PrintAndLogEx(ERR, "Card not in iso14443-4. res=%" PRId64 ".", resp.oldarg[0]); - DropField(); return 1; } @@ -591,13 +583,11 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav SendCommandOLD(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0, rats, 2); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (!silentMode) PrintAndLogEx(ERR, "Proxmark3 connection timeout."); - DropField(); return 1; } if (resp.oldarg[0] == 0) { // ats_len if (!silentMode) PrintAndLogEx(ERR, "Can't get ATS."); - DropField(); return 1; } } @@ -620,7 +610,6 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav if (!iLen) { if (!silentMode) PrintAndLogEx(ERR, "No card response."); - DropField(); return 1; } @@ -630,13 +619,11 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav if (maxdataoutlen && *dataoutlen > maxdataoutlen) { if (!silentMode) PrintAndLogEx(ERR, "Buffer too small(%d). Needs %d bytes", *dataoutlen, maxdataoutlen); - DropField(); return 2; } if (recv[0] != data[0]) { if (!silentMode) PrintAndLogEx(ERR, "iso14443-4 framing error. Card send %2x must be %2x", dataout[0], data[0]); - DropField(); return 2; } @@ -645,13 +632,11 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav // CRC Check if (iLen == -1) { if (!silentMode) PrintAndLogEx(ERR, "ISO 14443A CRC error."); - DropField(); return 3; } } else { if (!silentMode) PrintAndLogEx(ERR, "Reply timeout."); - DropField(); return 4; } @@ -672,20 +657,17 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(ERR, "Proxmark3 connection timeout."); - DropField(); return 1; } // check result if (resp.oldarg[0] == 0) { PrintAndLogEx(ERR, "No card in field."); - DropField(); return 1; } if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) { PrintAndLogEx(ERR, "Card not in iso14443-4. res=%" PRId64 ".", resp.oldarg[0]); - DropField(); return 1; } @@ -695,13 +677,11 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) { SendCommandOLD(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, sizeof(rats), 0, rats, sizeof(rats)); if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { PrintAndLogEx(ERR, "Proxmark3 connection timeout."); - DropField(); return 1; } if (resp.oldarg[0] == 0) { // ats_len PrintAndLogEx(ERR, "Can't get ATS."); - DropField(); return 1; } @@ -779,21 +759,18 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool if (!iLen) { PrintAndLogEx(ERR, "APDU: No APDU response."); - DropField(); return 1; } // check apdu length if (iLen < 2 && iLen >= 0) { PrintAndLogEx(ERR, "APDU: Small APDU response. Len=%d", iLen); - DropField(); return 2; } // check block TODO if (iLen == -2) { PrintAndLogEx(ERR, "APDU: Block type mismatch."); - DropField(); return 2; } @@ -807,12 +784,10 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool // CRC Check if (iLen == -1) { PrintAndLogEx(ERR, "APDU: ISO 14443A CRC error."); - DropField(); return 3; } } else { PrintAndLogEx(ERR, "APDU: Reply timeout."); - DropField(); return 4; } @@ -1174,15 +1149,12 @@ static int waitCmd(uint8_t iSelect) { PrintAndLogEx(NORMAL, "received %i bytes", len); } - if (!len) { - DropField(); + if (!len) return 1; - } PrintAndLogEx(NORMAL, "%s", sprint_hex(resp.data.asBytes, len)); } else { PrintAndLogEx(WARNING, "timeout while waiting for reply."); - DropField(); return 3; } return 0; From 3519dea0cf2cf50c04e448f9e473f85d8ff9b206 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 6 Apr 2020 15:25:56 +0200 Subject: [PATCH 5/5] simpler --- client/cmdhf14a.c | 64 +++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index eda2d3a3f..7fb267aa5 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -1421,38 +1421,30 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { // Double & triple sized UID, can be mapped to a manufacturer. if (card.uidlen <= 4) { nxptype = detect_nxp_card(card.sak, ((card.atqa[1] << 8) + card.atqa[0])); - if ((nxptype & MTCLASSIC) == MTCLASSIC) isMifareClassic = true; - else isMifareClassic = false; - if ((nxptype & MTDESFIRE) == MTDESFIRE) { - isMifareDESFire = true; - } else { - isMifareDESFire = false; - } - if ((nxptype & MTPLUS) == MTPLUS) isMifarePlus = true; - else isMifarePlus = false; - if ((nxptype & MTULTRALIGHT) == MTULTRALIGHT) isMifareUltralight = true; - else isMifareUltralight = false; - if ((nxptype & MTOTHER) == MTOTHER) isMifareClassic = true; + + isMifareClassic = ((nxptype & MTCLASSIC) == MTCLASSIC); + isMifareDESFire = ((nxptype & MTDESFIRE) == MTDESFIRE); + isMifarePlus = ((nxptype & MTPLUS) == MTPLUS); + isMifareUltralight = ((nxptype & MTULTRALIGHT) == MTULTRALIGHT); + + if ((nxptype & MTOTHER) == MTOTHER) + isMifareClassic = true; } if (card.uidlen > 4) { PrintAndLogEx(SUCCESS, "MANUFACTURER: " _YELLOW_("%s"), getTagInfo(card.uid[0])); - PrintAndLogEx(SUCCESS, "Possible Type:"); switch (card.uid[0]) { case 0x04: // NXP nxptype = detect_nxp_card(card.sak, ((card.atqa[1] << 8) + card.atqa[0])); - if ((nxptype & MTCLASSIC) == MTCLASSIC) isMifareClassic = true; - else isMifareClassic = false; - if ((nxptype & MTDESFIRE) == MTDESFIRE) { - isMifareDESFire = true; - } else { - isMifareDESFire = false; - } - if ((nxptype & MTPLUS) == MTPLUS) isMifarePlus = true; - else isMifarePlus = false; - if ((nxptype & MTULTRALIGHT) == MTULTRALIGHT) isMifareUltralight = true; - else isMifareUltralight = false; - if ((nxptype & MTOTHER) == MTOTHER) isMifareClassic = true; + + isMifareClassic = ((nxptype & MTCLASSIC) == MTCLASSIC); + isMifareDESFire = ((nxptype & MTDESFIRE) == MTDESFIRE); + isMifarePlus = ((nxptype & MTPLUS) == MTPLUS); + isMifareUltralight = ((nxptype & MTULTRALIGHT) == MTULTRALIGHT); + + if ((nxptype & MTOTHER) == MTOTHER) + isMifareClassic = true; + break; case 0x05: // Infineon if ((card.uid[1] & 0xF0) == 0x10) { @@ -1473,7 +1465,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { default: getTagLabel(card.uid[0], card.uid[1]); switch (card.sak) { - case 0x00: + case 0x00: { isMifareClassic = false; // ******** is card of the MFU type (UL/ULC/NTAG/ etc etc) @@ -1502,23 +1494,30 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { return select_status; } break; - case 0x0A: + } + case 0x0A: { printTag("FM11RF005SH (Shanghai Metro)"); break; - case 0x20: + } + case 0x20: { printTag("JCOP 31/41"); break; - case 0x28: + } + case 0x28: { printTag("JCOP31 or JCOP41 v2.3.1"); break; - case 0x38: + } + case 0x38: { printTag("Nokia 6212 or 6131"); break; - case 0x98: + } + case 0x98: { printTag("Gemplus MPCOS"); break; - default: + } + default: { break; + } } break; } @@ -1784,5 +1783,6 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) { } } + DropField(); return select_status; }