From 305903c5136aafb5b1a596937187f276d761743d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 3 May 2021 09:35:38 +0200 Subject: [PATCH] rework ISO15693 defines, removing duplicates --- armsrc/iso15693.c | 39 +++++++++++++++++---------------------- client/src/cmdhf15.c | 35 ++++++++++++++++++----------------- common/iso15693tools.h | 41 ----------------------------------------- 3 files changed, 35 insertions(+), 80 deletions(-) diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 42edf63e9..6602482fe 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -58,6 +58,7 @@ #include "util.h" #include "string.h" #include "iso15693tools.h" +#include "protocols.h" #include "cmd.h" #include "appmain.h" #include "dbprint.h" @@ -1444,7 +1445,7 @@ static void BuildIdentifyRequest(uint8_t *cmd) { // flags cmd[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1; // inventory command code - cmd[1] = ISO15_CMD_INVENTORY; + cmd[1] = ISO15693_INVENTORY; // no mask cmd[2] = 0x00; // CRC @@ -1723,7 +1724,7 @@ void SimTagIso15693(uint8_t *uid) { } // TODO: check more flags - if ((cmd_len >= 5) && (cmd[0] & ISO15_REQ_INVENTORY) && (cmd[1] == ISO15_CMD_INVENTORY)) { + if ((cmd_len >= 5) && (cmd[0] & ISO15_REQ_INVENTORY) && (cmd[1] == ISO15693_INVENTORY)) { bool slow = !(cmd[0] & ISO15_REQ_DATARATE_HIGH); uint32_t response_time = reader_eof_time + DELAY_ISO15693_VCD_TO_VICC_SIM; @@ -1756,7 +1757,7 @@ void SimTagIso15693(uint8_t *uid) { } // GET_SYSTEM_INFO - if ((cmd[1] == ISO15_CMD_SYSINFO)) { + if ((cmd[1] == ISO15693_GET_SYSTEM_INFO)) { bool slow = !(cmd[0] & ISO15_REQ_DATARATE_HIGH); uint32_t response_time = reader_eof_time + DELAY_ISO15693_VCD_TO_VICC_SIM; @@ -1794,7 +1795,7 @@ void SimTagIso15693(uint8_t *uid) { } // READ_BLOCK - if ((cmd[1] == ISO15_CMD_READ)) { + if ((cmd[1] == ISO15693_READBLOCK)) { bool slow = !(cmd[0] & ISO15_REQ_DATARATE_HIGH); uint32_t response_time = reader_eof_time + DELAY_ISO15693_VCD_TO_VICC_SIM; @@ -1838,7 +1839,7 @@ void BruteforceIso15693Afi(uint32_t speed) { // Tags should respond wihtout AFI and with AFI=0 even when AFI is active data[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1; - data[1] = ISO15_CMD_INVENTORY; + data[1] = ISO15693_INVENTORY; data[2] = 0; // AFI AddCrc15(data, 3); @@ -1909,13 +1910,13 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint bool request_answer = false; switch (data[1]) { - case ISO15_CMD_WRITE: - case ISO15_CMD_LOCK: - case ISO15_CMD_WRITEMULTI: - case ISO15_CMD_WRITEAFI: - case ISO15_CMD_LOCKAFI: - case ISO15_CMD_WRITEDSFID: - case ISO15_CMD_LOCKDSFID: + case ISO15693_WRITEBLOCK: + case ISO15693_LOCKBLOCK: + case ISO15693_WRITE_MULTI_BLOCK: + case ISO15693_WRITE_AFI: + case ISO15693_LOCK_AFI: + case ISO15693_WRITE_DSFID: + case ISO15693_LOCK_DSFID: timeout = ISO15693_READER_TIMEOUT_WRITE; request_answer = data[0] & ISO15_REQ_OPTION; break; @@ -2054,13 +2055,7 @@ void LockPassSlixIso15693(uint32_t pass_id, uint32_t password) { } Dbprintf("LockPass: Finishing"); - FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - cmd_send(CMD_ACK, recvlen, 0, 0, recvbuf, recvlen); - LED_A_OFF(); - LED_B_OFF(); - LED_C_OFF(); - LED_D_OFF(); } */ @@ -2075,10 +2070,10 @@ void SetTag15693Uid(uint8_t *uid) { LED_A_ON(); uint8_t cmd[4][9] = { - {ISO15_REQ_DATARATE_HIGH, ISO15_CMD_WRITE, 0x3e, 0x00, 0x00, 0x00, 0x00}, - {ISO15_REQ_DATARATE_HIGH, ISO15_CMD_WRITE, 0x3f, 0x69, 0x96, 0x00, 0x00}, - {ISO15_REQ_DATARATE_HIGH, ISO15_CMD_WRITE, 0x38}, - {ISO15_REQ_DATARATE_HIGH, ISO15_CMD_WRITE, 0x39} + {ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3e, 0x00, 0x00, 0x00, 0x00}, + {ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3f, 0x69, 0x96, 0x00, 0x00}, + {ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x38}, + {ISO15_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x39} }; // Command 3 : 02 21 38 u8u7u6u5 (where uX = uid byte X) diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index 0ec853b3a..3f9ff8e66 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -24,11 +24,12 @@ // variant, but offers the possibility to analyze the waveforms directly. #include "cmdhf15.h" #include -#include "cmdparser.h" // command_t -#include "commonutil.h" // ARRAYLEN -#include "comms.h" // clearCommandBuffer +#include "cmdparser.h" // command_t +#include "commonutil.h" // ARRAYLEN +#include "comms.h" // clearCommandBuffer #include "cmdtrace.h" -#include "iso15693tools.h" +#include "iso15693tools.h" // ISO15693 error codes etc +#include "protocols.h" // ISO15693 command set #include "crypto/libpcrypto.h" #include "graph.h" #include "crc16.h" // iso15 crc @@ -408,7 +409,7 @@ static int getUID(bool loop, uint8_t *buf) { uint8_t data[5]; data[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1; - data[1] = ISO15_CMD_INVENTORY; + data[1] = ISO15693_INVENTORY; data[2] = 0; // mask length AddCrc15(data, 3); @@ -648,7 +649,7 @@ static int NxpSysInfo(uint8_t *uid) { uint16_t reqlen = 0; req[reqlen++] |= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS; - req[reqlen++] = ISO15_CMD_GETNXPSYSTEMINFO; + req[reqlen++] = ISO15693_GET_SYSTEM_INFO; req[reqlen++] = 0x04; // IC manufacturer code memcpy(req + 3, uid, 8); // add UID reqlen += 8; @@ -719,7 +720,7 @@ static int NxpSysInfo(uint8_t *uid) { if (support_easmode) { reqlen = 0; req[reqlen++] |= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS; - req[reqlen++] = ISO15_CMD_EASALARM; + req[reqlen++] = ISO15693_EAS_ALARM; req[reqlen++] = 0x04; // IC manufacturer code memcpy(req + 3, uid, 8); // add UID reqlen += 8; @@ -753,7 +754,7 @@ static int NxpSysInfo(uint8_t *uid) { // Check if we can also read the signature reqlen = 0; req[reqlen++] |= ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_NONINVENTORY | ISO15_REQ_ADDRESS; - req[reqlen++] = ISO15_CMD_READSIGNATURE; + req[reqlen++] = ISO15693_READ_SIGNATURE; req[reqlen++] = 0x04; // IC manufacturer code memcpy(req + 3, uid, 8); // add UID reqlen += 8; @@ -764,7 +765,7 @@ static int NxpSysInfo(uint8_t *uid) { clearCommandBuffer(); SendCommandMIX(CMD_HF_ISO15693_COMMAND, reqlen, fast, reply, req, reqlen); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) { PrintAndLogEx(WARNING, "iso15693 timeout"); DropField(); return PM3_ETIMEOUT; @@ -837,7 +838,7 @@ static int CmdHF15Info(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[PM3_CMD_DATA_SIZE] = {flags, ISO15_CMD_SYSINFO}; + uint8_t req[PM3_CMD_DATA_SIZE] = {flags, ISO15693_GET_SYSTEM_INFO}; uint16_t reqlen = 2; if (scan) { @@ -1107,7 +1108,7 @@ static int CmdHF15WriteAfi(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[16] = {flags, ISO15_CMD_WRITEAFI}; + uint8_t req[16] = {flags, ISO15693_WRITE_AFI}; uint16_t reqlen = 2; if (unaddressed == false) { @@ -1204,7 +1205,7 @@ static int CmdHF15WriteDsfid(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[16] = {flags, ISO15_CMD_WRITEDSFID}; + uint8_t req[16] = {flags, ISO15693_WRITE_DSFID}; // enforce, since we are writing req[0] |= ISO15_REQ_OPTION; uint16_t reqlen = 2; @@ -1314,7 +1315,7 @@ static int CmdHF15Dump(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[13] = {flags, ISO15_CMD_READ}; + uint8_t req[13] = {flags, ISO15693_READBLOCK}; uint16_t reqlen = 2; if (scan) { @@ -1547,7 +1548,7 @@ static int CmdHF15Readmulti(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[PM3_CMD_DATA_SIZE] = {flags, ISO15_CMD_READMULTI}; + uint8_t req[PM3_CMD_DATA_SIZE] = {flags, ISO15693_READ_MULTI_BLOCK}; uint16_t reqlen = 2; if (unaddressed == false) { @@ -1681,7 +1682,7 @@ static int CmdHF15Readblock(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[PM3_CMD_DATA_SIZE] = {flags, ISO15_CMD_READ}; + uint8_t req[PM3_CMD_DATA_SIZE] = {flags, ISO15693_READBLOCK}; uint16_t reqlen = 2; if (unaddressed == false) { @@ -1858,7 +1859,7 @@ static int CmdHF15Write(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[17] = {flags, ISO15_CMD_WRITE}; + uint8_t req[17] = {flags, ISO15693_WRITEBLOCK}; // enforce, since we are writing req[0] |= ISO15_REQ_OPTION; @@ -1952,7 +1953,7 @@ static int CmdHF15Restore(const char *Cmd) { // request to be sent to device/card uint16_t flags = arg_get_raw_flag(uidlen, unaddressed, scan, add_option); - uint8_t req[17] = {flags, ISO15_CMD_WRITE}; + uint8_t req[17] = {flags, ISO15693_WRITEBLOCK}; // enforce, since we are writing req[0] |= ISO15_REQ_OPTION; uint16_t reqlen = 2; diff --git a/common/iso15693tools.h b/common/iso15693tools.h index 1096b501a..bce7eb68d 100644 --- a/common/iso15693tools.h +++ b/common/iso15693tools.h @@ -50,47 +50,6 @@ #define ISO15_ERROR_BLOCK_WRITE 0x13 // Writing was unsuccessful #define ISO15_ERROR_BLOCL_WRITELOCK 0x14 // Locking was unsuccessful -// COMMAND CODES -#define ISO15_CMD_INVENTORY 0x01 -#define ISO15_CMD_STAYQUIET 0x02 -#define ISO15_CMD_READ 0x20 -#define ISO15_CMD_WRITE 0x21 -#define ISO15_CMD_LOCK 0x22 -#define ISO15_CMD_READMULTI 0x23 -#define ISO15_CMD_WRITEMULTI 0x24 -#define ISO15_CMD_SELECT 0x25 -#define ISO15_CMD_RESET 0x26 -#define ISO15_CMD_WRITEAFI 0x27 -#define ISO15_CMD_LOCKAFI 0x28 -#define ISO15_CMD_WRITEDSFID 0x29 -#define ISO15_CMD_LOCKDSFID 0x2A -#define ISO15_CMD_SYSINFO 0x2B -#define ISO15_CMD_SECSTATUS 0x2C -#define ISO15_CMD_INVENTORYREAD 0xA0 -#define ISO15_CMD_FASTINVENTORYREAD 0xA1 -#define ISO15_CMD_SETEAS 0xA2 -#define ISO15_CMD_RESETEAS 0xA3 -#define ISO15_CMD_LOCKEAS 0xA4 -#define ISO15_CMD_EASALARM 0xA5 -#define ISO15_CMD_PASSWORDPROTECTEAS 0xA6 -#define ISO15_CMD_WRITEEASID 0xA7 -#define ISO15_CMD_READEPC 0xA8 -#define ISO15_CMD_GETNXPSYSTEMINFO 0xAB -#define ISO15_CMD_INVENTORYPAGEREAD 0xB0 -#define ISO15_CMD_FASTINVENTORYPAGEREAD 0xB1 -#define ISO15_CMD_GETRANDOMNUMBER 0xB2 -#define ISO15_CMD_SETPASSWORD 0xB3 -#define ISO15_CMD_WRITEPASSWORD 0xB4 -#define ISO15_CMD_LOCKPASSWORD 0xB5 -#define ISO15_CMD_PROTECTPAGE 0xB6 -#define ISO15_CMD_LOCKPAGEPROTECTION 0xB7 -#define ISO15_CMD_GETMULTIBLOCKPROTECTION 0xB8 -#define ISO15_CMD_DESTROY 0xB9 -#define ISO15_CMD_ENABLEPRIVACY 0xBA -#define ISO15_CMD_64BITPASSWORDPROTECTION 0xBB -#define ISO15_CMD_STAYQUIETPERSISTENT 0xBC -#define ISO15_CMD_READSIGNATURE 0xBD - //----------------------------------------------------------------------------- // Map a sequence of octets (~layer 2 command) into the set of bits to feed // to the FPGA, to transmit that command to the tag.