had to keep track if the field is on or off on deviceside for 14b raw.\nAdded picopass ISO14443-B anticollision. It allows us to send raw packages over 14b.

This commit is contained in:
iceman1001 committed 2024-01-16 15:12:16 +01:00
1 parent aa173ce94f
commit 2981dd94f7
6 files changed
+239 -21

No files matched your search

+80 -13
View File
@@ -20,19 +20,20 @@
#include <ctype.h>
#include "iso14b.h"
#include "fileutils.h"
#include "cmdparser.h" // command_t
#include "commonutil.h" // ARRAYLEN
#include "comms.h" // clearCommandBuffer
#include "emv/emvcore.h" // TLVPrintFromBuffer
#include "cmdparser.h" // command_t
#include "commonutil.h" // ARRAYLEN
#include "comms.h" // clearCommandBuffer
#include "emv/emvcore.h" // TLVPrintFromBuffer
#include "cmdtrace.h"
#include "cliparser.h"
#include "crc16.h"
#include "cmdhf14a.h"
#include "protocols.h" // definitions of ISO14B/7816 protocol
#include "iso7816/apduinfo.h" // GetAPDUCodeDescription
#include "nfc/ndef.h" // NDEFRecordsDecodeAndPrint
#include "protocols.h" // definitions of ISO14B/7816 protocol
#include "iso7816/apduinfo.h" // GetAPDUCodeDescription
#include "nfc/ndef.h" // NDEFRecordsDecodeAndPrint
#include "aidsearch.h"
#include "fileutils.h" // saveFile
#include "fileutils.h" // saveFile
#include "iclass_cmd.h" // picopass defines
#define MAX_14B_TIMEOUT_MS (4949U)
@@ -849,7 +850,7 @@ static int CmdHF14BSniff(const char *Cmd) {
return PM3_SUCCESS;
}
static int CmdHF14BCmdRaw(const char *Cmd) {
static int CmdHF14BRaw(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14b raw",
"Sends raw bytes to card. Activates field by default",
@@ -872,10 +873,9 @@ static int CmdHF14BCmdRaw(const char *Cmd) {
arg_lit0(NULL, "sr", "use SRx ST select"),
arg_lit0(NULL, "cts", "use ASK C-ticket select"),
arg_lit0(NULL, "xrx", "use Fuji/Xerox select"),
arg_lit0(NULL, "pico", "use Picopass select"),
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
@@ -894,7 +894,8 @@ static int CmdHF14BCmdRaw(const char *Cmd) {
bool select_sr = arg_get_lit(ctx, 8);
bool select_cts = arg_get_lit(ctx, 9);
bool select_xrx = arg_get_lit(ctx, 10);
bool verbose = arg_get_lit(ctx, 11);
bool select_pico = arg_get_lit(ctx, 11);
bool verbose = arg_get_lit(ctx, 12);
CLIParserFree(ctx);
// FLAGS for device side
@@ -928,6 +929,11 @@ static int CmdHF14BCmdRaw(const char *Cmd) {
if (verbose) {
PrintAndLogEx(INFO, "using Fuji/Xerox select");
}
} else if (select_pico) {
flags |= (ISO14B_CONNECT | ISO14B_SELECT_PICOPASS | ISO14B_CLEARTRACE);
if (verbose) {
PrintAndLogEx(INFO, "using Picopass select");
}
}
uint32_t time_wait = 0;
@@ -1008,6 +1014,13 @@ static int CmdHF14BCmdRaw(const char *Cmd) {
}
}
if (select_pico) {
success = wait_cmd_14b(verbose, true, user_timeout);
if (verbose && success) {
PrintAndLogEx(SUCCESS, "Got response for Picopass select");
}
}
// get back response from the raw bytes you sent.
if (success && datalen > 0) {
wait_cmd_14b(true, false, user_timeout);
@@ -1315,6 +1328,53 @@ static bool HF14B_ask_ct_reader(bool verbose) {
return false;
}
static bool HF14B_picopass_reader(bool verbose) {
iso14b_raw_cmd_t packet = {
.flags = (ISO14B_CONNECT | ISO14B_SELECT_PICOPASS | ISO14B_DISCONNECT),
.timeout = 0,
.rawlen = 0,
};
// 14b get and print UID only (general info)
clearCommandBuffer();
PacketResponseNG resp;
SendCommandNG(CMD_HF_ISO14443B_COMMAND, (uint8_t *)&packet, sizeof(iso14b_raw_cmd_t));
if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, TIMEOUT) == false) {
if (verbose) PrintAndLogEx(WARNING, "timeout while waiting for reply");
return false;
}
switch (resp.status) {
case PM3_SUCCESS: {
picopass_hdr_t *card = calloc(1, sizeof(picopass_hdr_t));
if (card == NULL) {
PrintAndLogEx(FAILED, "failed to allocate memory");
return false;
}
memcpy(card, resp.data.asBytes, sizeof(picopass_hdr_t));
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(SUCCESS, "iCLASS / Picopass CSN: " _GREEN_("%s"), sprint_hex(card->csn, sizeof(card->csn)));
free(card);
return true;
}
case PM3_ELENGTH: {
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-3 wrong length");
break;
}
case PM3_ECRC: {
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-3 CRC fail");
break;
}
default: {
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-b Picopass select failed");
break;
}
}
return false;
}
// test for other 14b type tags (mimic another reader - don't have tags to identify)
static bool HF14B_other_reader(bool verbose) {
@@ -2422,7 +2482,7 @@ static command_t CommandTable[] = {
{"dump", CmdHF14BDump, IfPm3Iso14443b, "Read all memory pages of an ISO-14443-B tag, save to file"},
{"info", CmdHF14Binfo, IfPm3Iso14443b, "Tag information"},
{"ndefread", CmdHF14BNdefRead, IfPm3Iso14443b, "Read NDEF file on tag"},
{"raw", CmdHF14BCmdRaw, IfPm3Iso14443b, "Send raw hex data to tag"},
{"raw", CmdHF14BRaw, IfPm3Iso14443b, "Send raw hex data to tag"},
{"rdbl", CmdHF14BSriRdBl, IfPm3Iso14443b, "Read SRI512/SRIX4 block"},
{"reader", CmdHF14BReader, IfPm3Iso14443b, "Act as a ISO-14443-B reader to identify a tag"},
// {"restore", CmdHF14BRestore, IfPm3Iso14443b, "Restore from file to all memory pages of an ISO-14443-B tag"},
@@ -2497,6 +2557,13 @@ int readHF14B(bool loop, bool verbose) {
else if (found)
return PM3_SUCCESS;
// Picopass
found |= HF14B_picopass_reader(verbose) ;
if (found && loop)
continue;
else if (found)
return PM3_SUCCESS;
} while (loop && kbd_enter_pressed() == false);
if (verbose && found == false) {