From: pwpiwi Date: Fri, 20 Dec 2019 07:25:14 +0000 (+0100) Subject: fix 'hf 15 csetuid' (#890) X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/1f4789fe53888e9ce01ab303fc10f6c19438ecc5?ds=sidebyside;hp=e73c9f1bd4f09495fc4a92607cc59943bcc56497 fix 'hf 15 csetuid' (#890) * fix 'hf 15 csetuid' * check for error codes, prevent client crash * some include file refactoring * some whitespace fixes * allow longer timeout for write commands * add function to send EOF only * modify 'hf list 15' to display "" * add tracing of Reader commands * if REQ_OPTION is set on write commands, send separate EOF to request tag response * use #defines instead of hex constants * switch off field after UID update * return last tag response (if there is any) * iso15693: decode WRITE_MULTI_BLOCK in 'hf list 15' --- diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index f10b0206..351b0184 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -75,6 +75,12 @@ #define DELAY_TAG_TO_ARM_SNOOP 32 #define DELAY_READER_TO_ARM_SNOOP 32 +// times in samples @ 212kHz when acting as reader +//#define ISO15693_READER_TIMEOUT 80 // 80/212kHz = 378us, nominal t1_max=313,9us +#define ISO15693_READER_TIMEOUT 330 // 330/212kHz = 1558us, should be even enough for iClass tags responding to ACTALL +#define ISO15693_READER_TIMEOUT_WRITE 4700 // 4700/212kHz = 22ms, nominal 20ms + + static int DEBUG = 0; @@ -140,6 +146,15 @@ void CodeIso15693AsReader(uint8_t *cmd, int n) { ToSendMax++; } + +// Encode EOF only +static void CodeIso15693AsReaderEOF() { + ToSendReset(); + ToSend[++ToSendMax] = 0x20; + ToSendMax++; +} + + // encode data using "1 out of 256" scheme // data rate is 1,66 kbit/s (fc/8192) // is designed for more robust communication over longer distances @@ -1105,16 +1120,12 @@ int GetIso15693CommandFromReader(uint8_t *received, size_t max_len, uint32_t *eo } -// Encode (into the ToSend buffers) an identify request, which is the first +// Construct an identify (Inventory) request, which is the first // thing that you must send to a tag to get a response. -static void BuildIdentifyRequest(void) -{ - uint8_t cmd[5]; - +static void BuildIdentifyRequest(uint8_t *cmd) { uint16_t crc; // one sub-carrier, inventory, 1 slot, fast rate - // AFI is at bit 5 (1<<4) when doing an INVENTORY - cmd[0] = (1 << 2) | (1 << 5) | (1 << 1); + cmd[0] = ISO15693_REQ_INVENTORY | ISO15693_REQINV_SLOT1 | ISO15693_REQ_DATARATE_HIGH; // inventory command code cmd[1] = 0x01; // no mask @@ -1123,8 +1134,6 @@ static void BuildIdentifyRequest(void) crc = Iso15693Crc(cmd, 3); cmd[3] = crc & 0xff; cmd[4] = crc >> 8; - - CodeIso15693AsReader(cmd, sizeof(cmd)); } @@ -1133,8 +1142,7 @@ static void BuildIdentifyRequest(void) // for the response. The response is not demodulated, just left in the buffer // so that it can be downloaded to a PC and processed there. //----------------------------------------------------------------------------- -void AcquireRawAdcSamplesIso15693(void) -{ +void AcquireRawAdcSamplesIso15693(void) { LED_A_ON(); uint8_t *dest = BigBuf_get_addr(); @@ -1145,7 +1153,9 @@ void AcquireRawAdcSamplesIso15693(void) FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER); SetAdcMuxFor(GPIO_MUXSEL_HIPKD); - BuildIdentifyRequest(); + uint8_t cmd[5]; + BuildIdentifyRequest(cmd); + CodeIso15693AsReader(cmd, sizeof(cmd)); // Give the tags time to energize SpinDelay(100); @@ -1371,10 +1381,7 @@ void Iso15693InitReader() { // uid is in transmission order (which is reverse of display order) -static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber ) -{ - uint8_t cmd[13]; - +static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber, uint8_t *cmd) { uint16_t crc; // If we set the Option_Flag in this request, the VICC will respond with the security status of the block // followed by the block data @@ -1398,13 +1405,11 @@ static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber ) cmd[11] = crc & 0xff; cmd[12] = crc >> 8; - CodeIso15693AsReader(cmd, sizeof(cmd)); } // Now the VICC>VCD responses when we are simulating a tag -static void BuildInventoryResponse(uint8_t *uid) -{ +static void BuildInventoryResponse(uint8_t *uid) { uint8_t cmd[12]; uint16_t crc; @@ -1433,7 +1438,7 @@ static void BuildInventoryResponse(uint8_t *uid) // speed ... 0 low speed, 1 hi speed // *recv will contain the tag's answer // return: length of received data, or -1 for timeout -int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint32_t *eof_time) { +int SendDataTag(uint8_t *send, int sendlen, bool init, bool speed_fast, uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time) { if (init) { Iso15693InitReader(); @@ -1442,19 +1447,40 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *recv, int answerLen = 0; - if (!speed) { - // low speed (1 out of 256) - CodeIso15693AsReader256(send, sendlen); - } else { + if (speed_fast) { // high speed (1 out of 4) CodeIso15693AsReader(send, sendlen); + } else { + // low speed (1 out of 256) + CodeIso15693AsReader256(send, sendlen); } TransmitTo15693Tag(ToSend, ToSendMax, &start_time); + uint32_t end_time = start_time + 32*(8*ToSendMax-4); // substract the 4 padding bits after EOF + LogTrace_ISO15693(send, sendlen, start_time*4, end_time*4, NULL, true); + + // Now wait for a response + if (recv != NULL) { + answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, timeout, eof_time); + } + + return answerLen; +} + + +int SendDataTagEOF(uint8_t *recv, uint16_t max_recv_len, uint32_t start_time, uint16_t timeout, uint32_t *eof_time) { + + int answerLen = 0; + + CodeIso15693AsReaderEOF(); + + TransmitTo15693Tag(ToSend, ToSendMax, &start_time); + uint32_t end_time = start_time + 32*(8*ToSendMax-4); // substract the 4 padding bits after EOF + LogTrace_ISO15693(NULL, 0, start_time*4, end_time*4, NULL, true); // Now wait for a response if (recv != NULL) { - answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, ISO15693_READER_TIMEOUT, eof_time); + answerLen = GetIso15693AnswerFromTag(recv, max_recv_len, timeout, eof_time); } return answerLen; @@ -1546,7 +1572,6 @@ void ReaderIso15693(uint32_t parameter) { set_tracing(true); - int answerLen = 0; uint8_t TagUID[8] = {0x00}; FpgaDownloadAndGo(FPGA_BITSTREAM_HF); @@ -1572,17 +1597,14 @@ void ReaderIso15693(uint32_t parameter) { // THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME // Now send the IDENTIFY command - BuildIdentifyRequest(); + uint8_t cmd[5]; + BuildIdentifyRequest(cmd); uint32_t start_time = 0; - TransmitTo15693Tag(ToSend, ToSendMax, &start_time); - - // Now wait for a response uint32_t eof_time; - answerLen = GetIso15693AnswerFromTag(answer, sizeof(answer), DELAY_ISO15693_VCD_TO_VICC_READER * 2, &eof_time) ; + int answerLen = SendDataTag(cmd, sizeof(cmd), true, true, answer, sizeof(answer), start_time, ISO15693_READER_TIMEOUT, &eof_time); start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; - if (answerLen >=12) // we should do a better check than this - { + if (answerLen >= 12) { // we should do a better check than this TagUID[0] = answer[2]; TagUID[1] = answer[3]; TagUID[2] = answer[4]; @@ -1591,7 +1613,6 @@ void ReaderIso15693(uint32_t parameter) { TagUID[5] = answer[7]; TagUID[6] = answer[8]; // IC Manufacturer code TagUID[7] = answer[9]; // always E0 - } Dbprintf("%d octets read from IDENTIFY request:", answerLen); @@ -1604,21 +1625,12 @@ void ReaderIso15693(uint32_t parameter) { TagUID[7],TagUID[6],TagUID[5],TagUID[4], TagUID[3],TagUID[2],TagUID[1],TagUID[0]); - - // Dbprintf("%d octets read from SELECT request:", answerLen2); - // DbdecodeIso15693Answer(answerLen2,answer2); - // Dbhexdump(answerLen2,answer2,true); - - // Dbprintf("%d octets read from XXX request:", answerLen3); - // DbdecodeIso15693Answer(answerLen3,answer3); - // Dbhexdump(answerLen3,answer3,true); - // read all pages if (answerLen >= 12 && DEBUG) { for (int i = 0; i < 32; i++) { // sanity check, assume max 32 pages - BuildReadBlockRequest(TagUID, i); - TransmitTo15693Tag(ToSend, ToSendMax, &start_time); - int answerLen = GetIso15693AnswerFromTag(answer, sizeof(answer), DELAY_ISO15693_VCD_TO_VICC_READER * 2, &eof_time); + uint8_t cmd[13]; + BuildReadBlockRequest(TagUID, i, cmd); + answerLen = SendDataTag(cmd, sizeof(cmd), false, true, answer, sizeof(answer), start_time, ISO15693_READER_TIMEOUT, &eof_time); start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; if (answerLen > 0) { Dbprintf("READ SINGLE BLOCK %d returned %d octets:", i, answerLen); @@ -1629,7 +1641,7 @@ void ReaderIso15693(uint32_t parameter) { } } - // for the time being, switch field off to protect rdv4.0 + // for the time being, switch field off to protect RDV4 // note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LED_D_OFF(); @@ -1680,8 +1692,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid) { // Since there is no standardized way of reading the AFI out of a tag, we will brute force it // (some manufactures offer a way to read the AFI, though) -void BruteforceIso15693Afi(uint32_t speed) -{ +void BruteforceIso15693Afi(uint32_t speed) { LED_A_ON(); uint8_t data[6]; @@ -1697,7 +1708,7 @@ void BruteforceIso15693Afi(uint32_t speed) data[2] = 0; // mask length datalen = Iso15693AddCrc(data,3); uint32_t start_time = GetCountSspClk(); - recvlen = SendDataTag(data, datalen, true, speed, recv, sizeof(recv), 0, &eof_time); + recvlen = SendDataTag(data, datalen, true, speed, recv, sizeof(recv), 0, ISO15693_READER_TIMEOUT, &eof_time); start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; WDT_HIT(); if (recvlen>=12) { @@ -1714,7 +1725,7 @@ void BruteforceIso15693Afi(uint32_t speed) for (int i = 0; i < 256; i++) { data[2] = i & 0xFF; datalen = Iso15693AddCrc(data,4); - recvlen = SendDataTag(data, datalen, false, speed, recv, sizeof(recv), start_time, &eof_time); + recvlen = SendDataTag(data, datalen, false, speed, recv, sizeof(recv), start_time, ISO15693_READER_TIMEOUT, &eof_time); start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; WDT_HIT(); if (recvlen >= 12) { @@ -1738,13 +1749,35 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint uint8_t recvbuf[ISO15693_MAX_RESPONSE_LENGTH]; uint32_t eof_time; + uint16_t timeout; + bool request_answer = false; + + switch (data[1]) { + 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] & ISO15693_REQ_OPTION; + break; + default: + timeout = ISO15693_READER_TIMEOUT; + } + if (DEBUG) { Dbprintf("SEND:"); Dbhexdump(datalen, data, false); } - recvlen = SendDataTag(data, datalen, true, speed, (recv?recvbuf:NULL), sizeof(recvbuf), 0, &eof_time); + recvlen = SendDataTag(data, datalen, true, speed, (recv?recvbuf:NULL), sizeof(recvbuf), 0, timeout, &eof_time); + if (request_answer) { // send a single EOF to get the tag response + recvlen = SendDataTagEOF((recv?recvbuf:NULL), sizeof(recvbuf), 0, ISO15693_READER_TIMEOUT, &eof_time); + } + // for the time being, switch field off to protect rdv4.0 // note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); @@ -1772,16 +1805,16 @@ void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint // //----------------------------------------------------------------------------- -// Set the UID to the tag (based on Iceman work). +// Set the UID on Magic ISO15693 tag (based on Iceman's LUA-script). void SetTag15693Uid(uint8_t *uid) { LED_A_ON(); uint8_t cmd[4][9] = { - {0x02, 0x21, 0x3e, 0x00, 0x00, 0x00, 0x00}, - {0x02, 0x21, 0x3f, 0x69, 0x96, 0x00, 0x00}, - {0x02, 0x21, 0x38}, - {0x02, 0x21, 0x39} + {ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3e, 0x00, 0x00, 0x00, 0x00}, + {ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x3f, 0x69, 0x96, 0x00, 0x00}, + {ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x38}, + {ISO15693_REQ_DATARATE_HIGH, ISO15693_WRITEBLOCK, 0x39} }; uint16_t crc; @@ -1802,30 +1835,35 @@ void SetTag15693Uid(uint8_t *uid) { cmd[3][5] = uid[1]; cmd[3][6] = uid[0]; + uint32_t start_time = 0; + for (int i = 0; i < 4; i++) { // Add the CRC crc = Iso15693Crc(cmd[i], 7); cmd[i][7] = crc & 0xff; cmd[i][8] = crc >> 8; + recvlen = SendDataTag(cmd[i], sizeof(cmd[i]), i==0?true:false, true, recvbuf, sizeof(recvbuf), start_time, ISO15693_READER_TIMEOUT_WRITE, &eof_time); + start_time = eof_time + DELAY_ISO15693_VICC_TO_VCD_READER; if (DEBUG) { Dbprintf("SEND:"); Dbhexdump(sizeof(cmd[i]), cmd[i], false); - } - - recvlen = SendDataTag(cmd[i], sizeof(cmd[i]), true, 1, recvbuf, sizeof(recvbuf), 0, &eof_time); - - if (DEBUG) { Dbprintf("RECV:"); if (recvlen > 0) { Dbhexdump(recvlen, recvbuf, false); DbdecodeIso15693Answer(recvlen, recvbuf); } } - - cmd_send(CMD_ACK, recvlen>ISO15693_MAX_RESPONSE_LENGTH?ISO15693_MAX_RESPONSE_LENGTH:recvlen, 0, 0, recvbuf, ISO15693_MAX_RESPONSE_LENGTH); + // Note: need to know if we expect an answer from one of the magic commands + // if (recvlen < 0) { + // break; + // } } + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + LED_D_OFF(); + + cmd_send(CMD_ACK, recvlen, 0, 0, recvbuf, recvlen); LED_A_OFF(); } diff --git a/armsrc/iso15693.h b/armsrc/iso15693.h index 5175ff20..e48e4d4a 100644 --- a/armsrc/iso15693.h +++ b/armsrc/iso15693.h @@ -21,8 +21,6 @@ //SSP_CLK runs at 13.56MHz / 4 = 3,39MHz when acting as reader. All values should be multiples of 16 #define DELAY_ISO15693_VCD_TO_VICC_READER 1056 // 1056/3,39MHz = 311.5us from end of command EOF to start of tag response #define DELAY_ISO15693_VICC_TO_VCD_READER 1024 // 1024/3.39MHz = 302.1us between end of tag response and next reader command -// times in samples @ 212kHz when acting as reader -#define ISO15693_READER_TIMEOUT 330 // 330/212kHz = 1558us, should be even enough for iClass tags responding to ACTALL void Iso15693InitReader(); void CodeIso15693AsReader(uint8_t *cmd, int n); diff --git a/client/cmdhf15.c b/client/cmdhf15.c index 6bcad201..cc86841b 100644 --- a/client/cmdhf15.c +++ b/client/cmdhf15.c @@ -90,34 +90,32 @@ static const int Iso15693FrameEOF[] = { // fast method to just read the UID of a tag (collission detection not supported) // *buf should be large enough to fit the 64bit uid -// returns 1 if suceeded -int getUID(uint8_t *buf) -{ +// returns true if suceeded +static bool getUID(uint8_t *buf) { UsbCommand resp; uint8_t *recv; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? - uint8_t *req=c.d.asBytes; + uint8_t *req = c.d.asBytes; int reqlen=0; - for (int retry=0;retry<3; retry++) { // don't give up the at the first try - + for (int retry = 0;retry < 3; retry++) { // don't give up the at the first try req[0] = ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_INVENTORY | ISO15693_REQINV_SLOT1; req[1] = ISO15693_INVENTORY; req[2] = 0; // mask length - reqlen = AddCrc(req,3); + reqlen = AddCrc(req, 3); c.arg[0] = reqlen; SendCommand(&c); - if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) { + if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { recv = resp.d.asBytes; - if (resp.arg[0]>=12 && ISO15693_CRC_CHECK==Crc(recv,12)) { - memcpy(buf,&recv[2],8); - return 1; + if (resp.arg[0] >= 12 && ISO15693_CRC_CHECK == Crc(recv, 12)) { + memcpy(buf, &recv[2], 8); + return true; } } } // retry - return 0; + return false; } @@ -139,8 +137,7 @@ static char* TagErrorStr(uint8_t error) { // Mode 3 -int CmdHF15Demod(const char *Cmd) -{ +static int CmdHF15Demod(const char *Cmd) { // The sampling rate is 106.353 ksps/s, for T = 18.8 us int i, j; @@ -224,25 +221,23 @@ int CmdHF15Demod(const char *Cmd) } - // * Acquire Samples as Reader (enables carrier, sends inquiry) -int CmdHF15Read(const char *Cmd) -{ +static int CmdHF15Read(const char *Cmd) { UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693}; SendCommand(&c); return 0; } + // Record Activity without enabling carrier -int CmdHF15Snoop(const char *Cmd) -{ +static int CmdHF15Snoop(const char *Cmd) { UsbCommand c = {CMD_SNOOP_ISO_15693}; SendCommand(&c); return 0; } -int HF15Reader(const char *Cmd, bool verbose) -{ + +int HF15Reader(const char *Cmd, bool verbose) { uint8_t uid[8]; if (!getUID(uid)) { @@ -256,16 +251,16 @@ int HF15Reader(const char *Cmd, bool verbose) return 1; } -int CmdHF15Reader(const char *Cmd) -{ + +static int CmdHF15Reader(const char *Cmd) { UsbCommand c = {CMD_READER_ISO_15693, {strtol(Cmd, NULL, 0), 0, 0}}; SendCommand(&c); return 0; } + // Simulation is still not working very good -int CmdHF15Sim(const char *Cmd) -{ +static int CmdHF15Sim(const char *Cmd) { char cmdp = param_getchar(Cmd, 0); uint8_t uid[8] = {0x00}; @@ -293,17 +288,18 @@ int CmdHF15Sim(const char *Cmd) return 0; } + // finds the AFI (Application Family Idendifier) of a card, by trying all values // (There is no standard way of reading the AFI, allthough some tags support this) -int CmdHF15Afi(const char *Cmd) -{ +static int CmdHF15Afi(const char *Cmd) { UsbCommand c = {CMD_ISO_15693_FIND_AFI, {strtol(Cmd, NULL, 0), 0, 0}}; SendCommand(&c); return 0; } + // Reads all memory pages -int CmdHF15DumpMem(const char*Cmd) { +static int CmdHF15DumpMem(const char*Cmd) { UsbCommand resp; uint8_t uid[8]; uint8_t *recv=NULL; @@ -369,41 +365,7 @@ int CmdHF15DumpMem(const char*Cmd) { } -// "HF 15" interface - -static command_t CommandTable15[] = -{ - {"help", CmdHF15Help, 1, "This help"}, - {"demod", CmdHF15Demod, 1, "Demodulate ISO15693 from tag"}, - {"read", CmdHF15Read, 0, "Read HF tag (ISO 15693)"}, - {"snoop", CmdHF15Snoop, 0, "Eavesdrop ISO 15693 communications"}, - {"reader", CmdHF15Reader, 0, "Act like an ISO15693 reader"}, - {"sim", CmdHF15Sim, 0, "Fake an ISO15693 tag"}, - {"cmd", CmdHF15Cmd, 0, "Send direct commands to ISO15693 tag"}, - {"findafi", CmdHF15Afi, 0, "Brute force AFI of an ISO15693 tag"}, - {"dumpmemory", CmdHF15DumpMem, 0, "Read all memory pages of an ISO15693 tag"}, - {"csetuid", CmdHF15CSetUID, 0, "Set UID for magic Chinese card"}, - {NULL, NULL, 0, NULL} -}; - -int CmdHF15(const char *Cmd) -{ - CmdsParse(CommandTable15, Cmd); - return 0; -} - -int CmdHF15Help(const char *Cmd) -{ - CmdsHelp(CommandTable15); - return 0; -} - - -// "HF 15 Cmd" Interface -// Allows direct communication with the tag on command level - -int CmdHF15CmdInquiry(const char *Cmd) -{ +static int CmdHF15CmdInquiry(const char *Cmd) { UsbCommand resp; uint8_t *recv; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? @@ -435,7 +397,7 @@ int CmdHF15CmdInquiry(const char *Cmd) // Turns debugging on(1)/off(0) -int CmdHF15CmdDebug( const char *cmd) { +static int CmdHF15CmdDebug( const char *cmd) { int debug = atoi(cmd); if (strlen(cmd) < 1) { PrintAndLog("Usage: hf 15 debug <0|1>"); @@ -450,7 +412,7 @@ int CmdHF15CmdDebug( const char *cmd) { } -int CmdHF15CmdRaw (const char *cmd) { +static int CmdHF15CmdRaw (const char *cmd) { UsbCommand resp; uint8_t *recv; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? @@ -560,30 +522,30 @@ int CmdHF15CmdRaw (const char *cmd) { * Parameters: * **cmd command line */ -int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) { +static int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdlen) { int temp; - uint8_t *req=c->d.asBytes; + uint8_t *req = c->d.asBytes; uint8_t uid[8] = {0x00}; - uint32_t reqlen=0; + uint32_t reqlen = 0; // strip while (**cmd==' ' || **cmd=='\t') (*cmd)++; - if (strstr(*cmd,"-2")==*cmd) { - c->arg[1]=0; // use 1of256 - (*cmd)+=2; + if (strstr(*cmd, "-2") == *cmd) { + c->arg[1] = 0; // use 1of256 + (*cmd) += 2; } // strip - while (**cmd==' ' || **cmd=='\t') (*cmd)++; + while (**cmd == ' ' || **cmd == '\t') (*cmd)++; - if (strstr(*cmd,"-o")==*cmd) { - req[reqlen]=ISO15693_REQ_OPTION; - (*cmd)+=2; + if (strstr(*cmd, "-o") == *cmd) { + req[reqlen] = ISO15693_REQ_OPTION; + (*cmd) += 2; } // strip - while (**cmd==' ' || **cmd=='\t') (*cmd)++; + while (**cmd == ' ' || **cmd == '\t') (*cmd)++; switch (**cmd) { case 0: @@ -594,54 +556,54 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdle case 'S': // you must have selected the tag earlier req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_SELECT; - memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen); + memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen); reqlen += iso15cmdlen; break; case 'u': case 'U': // unaddressed mode may not be supported by all vendors req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH; - memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen); + memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen); reqlen += iso15cmdlen; break; case '*': // we scan for the UID ourself req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_ADDRESS; - memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen); - reqlen+=iso15cmdlen; + memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen); + reqlen += iso15cmdlen; if (!getUID(uid)) { PrintAndLog("No Tag found"); return 0; } - memcpy(req+reqlen,uid,8); + memcpy(req+reqlen ,uid, 8); PrintAndLog("Detected UID %s",sprintUID(NULL,uid)); - reqlen+=8; + reqlen += 8; break; default: req[reqlen++] |= ISO15693_REQ_DATARATE_HIGH | ISO15693_REQ_ADDRESS; - memcpy(&req[reqlen],&iso15cmd[0],iso15cmdlen); - reqlen+=iso15cmdlen; + memcpy(&req[reqlen], &iso15cmd[0], iso15cmdlen); + reqlen += iso15cmdlen; /* sscanf(cmd,"%hX%hX%hX%hX%hX%hX%hX%hX", (short unsigned int *)&uid[7],(short unsigned int *)&uid[6], (short unsigned int *)&uid[5],(short unsigned int *)&uid[4], (short unsigned int *)&uid[3],(short unsigned int *)&uid[2], (short unsigned int *)&uid[1],(short unsigned int *)&uid[0]); */ - for (int i=0;i<8 && (*cmd)[i*2] && (*cmd)[i*2+1];i++) { // parse UID + for (int i=0; i<8 && (*cmd)[i*2] && (*cmd)[i*2+1]; i++) { // parse UID sscanf((char[]){(*cmd)[i*2],(*cmd)[i*2+1],0},"%X",&temp); uid[7-i]=temp&0xff; } - PrintAndLog("Using UID %s",sprintUID(NULL,uid)); - memcpy(&req[reqlen],&uid[0],8); - reqlen+=8; + PrintAndLog("Using UID %s", sprintUID(NULL, uid)); + memcpy(&req[reqlen], &uid[0], 8); + reqlen += 8; } // skip to next space - while (**cmd!=' ' && **cmd!='\t') (*cmd)++; + while (**cmd != ' ' && **cmd != '\t') (*cmd)++; // skip over the space - while (**cmd==' ' || **cmd=='\t') (*cmd)++; + while (**cmd == ' ' || **cmd == '\t') (*cmd)++; - c->arg[0]=reqlen; + c->arg[0] = reqlen; return 1; } @@ -649,7 +611,7 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd[], int iso15cmdle * Commandline handling: HF15 CMD SYSINFO * get system information from tag/VICC */ -int CmdHF15CmdSysinfo(const char *Cmd) { +static int CmdHF15CmdSysinfo(const char *Cmd) { UsbCommand resp; uint8_t *recv; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? @@ -685,9 +647,9 @@ int CmdHF15CmdSysinfo(const char *Cmd) { SendCommand(&c); - if (WaitForResponseTimeout(CMD_ACK,&resp,1000) && resp.arg[0]>2) { + if (WaitForResponseTimeout(CMD_ACK, &resp, 1000) && resp.arg[0] > 2) { recv = resp.d.asBytes; - if (ISO15693_CRC_CHECK==Crc(recv,resp.arg[0])) { + if (ISO15693_CRC_CHECK == Crc(recv, resp.arg[0])) { if (!(recv[0] & ISO15693_RES_ERROR)) { *output=0; // reset outputstring PrintAndLog("UID: %s", sprintUID(NULL,recv+2)); @@ -727,11 +689,12 @@ int CmdHF15CmdSysinfo(const char *Cmd) { return 0; } + /** * Commandline handling: HF15 CMD READMULTI * Read multiple blocks at once (not all tags support this) */ -int CmdHF15CmdReadmulti(const char *Cmd) { +static int CmdHF15CmdReadmulti(const char *Cmd) { UsbCommand resp; uint8_t *recv; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? @@ -806,11 +769,12 @@ int CmdHF15CmdReadmulti(const char *Cmd) { return 0; } + /** * Commandline handling: HF15 CMD READ * Reads a single Block */ -int CmdHF15CmdRead(const char *Cmd) { +static int CmdHF15CmdRead(const char *Cmd) { UsbCommand resp; uint8_t *recv; UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? @@ -883,22 +847,21 @@ int CmdHF15CmdRead(const char *Cmd) { /** * Commandline handling: HF15 CMD WRITE - * Writes a single Block - might run into timeout, even when successful - */ -int CmdHF15CmdWrite(const char *Cmd) { + * Writes a single Block +**/ +static int CmdHF15CmdWrite(const char *Cmd) { UsbCommand resp; - uint8_t *recv; - UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv? - uint8_t *req=c.d.asBytes; - int reqlen=0, pagenum, temp; + UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len, speed, recv + uint8_t *req = c.d.asBytes; + int reqlen = 0, pagenum, temp; char cmdbuf[100]; - char *cmd=cmdbuf; + char *cmd = cmdbuf; char *cmd2; - strncpy(cmd,Cmd,99); + strncpy(cmd, Cmd, 99); // usage: - if (strlen(cmd)<3) { + if (strlen(cmd) < 3) { PrintAndLog("Usage: hf 15 cmd write [options] "); PrintAndLog(" options:"); PrintAndLog(" -2 use slower '1 out of 256' mode"); @@ -913,171 +876,207 @@ int CmdHF15CmdWrite(const char *Cmd) { return 0; } - prepareHF15Cmd(&cmd, &c,(uint8_t[]){ISO15693_WRITEBLOCK},1); - reqlen=c.arg[0]; + prepareHF15Cmd(&cmd, &c, (uint8_t[]){ISO15693_WRITEBLOCK}, 1); + reqlen = c.arg[0]; // *cmd -> page num ; *cmd2 -> data - cmd2=cmd; - while (*cmd2!=' ' && *cmd2!='\t' && *cmd2) cmd2++; - *cmd2=0; + cmd2 = cmd; + while (*cmd2 != ' ' && *cmd2 != '\t' && *cmd2) cmd2++; + *cmd2 = 0; cmd2++; - pagenum=strtol(cmd,NULL,0); + pagenum = strtol(cmd, NULL, 0); /*if (pagenum<0) { PrintAndLog("invalid pagenum"); return 0; } */ - req[reqlen++]=(uint8_t)pagenum; + req[reqlen++] = (uint8_t)pagenum; while (cmd2[0] && cmd2[1]) { // hexdata, read by 2 hexchars - if (*cmd2==' ') { + if (*cmd2 == ' ') { cmd2++; continue; } - sscanf((char[]){cmd2[0],cmd2[1],0},"%X",&temp); - req[reqlen++]=temp & 0xff; - cmd2+=2; + sscanf((char[]){cmd2[0], cmd2[1], 0}, "%X", &temp); + req[reqlen++] = temp & 0xff; + cmd2 += 2; } - reqlen=AddCrc(req,reqlen); - - c.arg[0]=reqlen; + reqlen = AddCrc(req, reqlen); + c.arg[0] = reqlen; SendCommand(&c); - if (WaitForResponseTimeout(CMD_ACK,&resp,2000) && resp.arg[0]>2) { - recv = resp.d.asBytes; - if (ISO15693_CRC_CHECK==Crc(recv,resp.arg[0])) { - if (!(recv[0] & ISO15693_RES_ERROR)) { - PrintAndLog("OK"); - } else { - PrintAndLog("Tag returned Error %i: %s",recv[1],TagErrorStr(recv[1])); - } + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + int recv_len = resp.arg[0]; + uint8_t *recv = resp.d.asBytes; + if (recv_len == 0) { + PrintAndLog("Received SOF only. Maybe Picopass/iCLASS?"); + } else if (recv_len == -1) { + PrintAndLog("Tag didn't respond"); + } else if (recv_len == -2) { + PrintAndLog("Receive buffer overflow"); + } else if (ISO15693_CRC_CHECK != Crc(recv, resp.arg[0])) { + PrintAndLog("CRC check failed on Tag response"); + } else if (!(recv[0] & ISO15693_RES_ERROR)) { + PrintAndLog("Tag returned OK"); } else { - PrintAndLog("CRC failed"); + PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1])); } } else { - PrintAndLog("timeout: no answer - data may be written anyway"); + PrintAndLog("No answer from Proxmark"); } return 0; } -int CmdHF15CSetUID(const char *Cmd) -{ - uint8_t uid[8] = {0x00}; - uint8_t oldUid[8], newUid[8] = {0x00}; - - uint8_t needHelp = 0; - char cmdp = 1; - - if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 16)) { - PrintAndLog("UID must include 16 HEX symbols"); - return 1; - } - - if (uid[0] != 0xe0) { - PrintAndLog("UID must begin with the byte 'E0'"); - return 1; - } - - while(param_getchar(Cmd, cmdp) != 0x00) - { - switch(param_getchar(Cmd, cmdp)) - { - case 'h': - case 'H': - needHelp = 1; - break; - default: - PrintAndLog("ERROR: Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - needHelp = 1; - break; - } - cmdp++; - } - - if (strlen(Cmd) < 1 || needHelp) { - PrintAndLog(""); - PrintAndLog("Usage: hf 15 csetuid "); - PrintAndLog("sample: hf 15 csetuid E004013344556677"); - PrintAndLog("Set UID for magic Chinese card (only works with such cards)"); - return 0; - } - - PrintAndLog(""); - PrintAndLog("new UID | %s", sprint_hex(uid, 8)); - PrintAndLog("Using backdoor Magic tag function"); - - if (!getUID(oldUid)) { - PrintAndLog("Can't get old UID."); - return 1; - } - - UsbCommand resp; - uint8_t *recv; - char *hexout; - UsbCommand c = {CMD_CSETUID_ISO_15693, {0, 0, 0}}; - memcpy(c.d.asBytes, uid, 8); + +static int CmdHF15CSetUID(const char *Cmd) { + uint8_t uid[8] = {0x00}; + uint8_t oldUid[8], newUid[8] = {0x00}; + + uint8_t needHelp = 0; + char cmdp = 1; + + if (param_getchar(Cmd, 0) && param_gethex(Cmd, 0, uid, 16)) { + PrintAndLog("UID must include 16 HEX symbols"); + return 1; + } + + if (uid[0] != 0xe0) { + PrintAndLog("UID must begin with the byte 'E0'"); + return 1; + } + + while (param_getchar(Cmd, cmdp) != 0x00) { + switch (param_getchar(Cmd, cmdp)) { + case 'h': + case 'H': + needHelp = 1; + break; + default: + PrintAndLog("ERROR: Unknown parameter '%c'", param_getchar(Cmd, cmdp)); + needHelp = 1; + break; + } + cmdp++; + } + + if (strlen(Cmd) < 1 || needHelp) { + PrintAndLog(""); + PrintAndLog("Usage: hf 15 csetuid "); + PrintAndLog("sample: hf 15 csetuid E004013344556677"); + PrintAndLog("Set UID for magic Chinese card (only works with such cards)"); + return 0; + } + + PrintAndLog("Using backdoor Magic tag function"); + + if (!getUID(oldUid)) { + PrintAndLog("Can't get old UID."); + return 1; + } + + UsbCommand c = {CMD_CSETUID_ISO_15693, {0, 0, 0}}; + memcpy(c.d.asBytes, uid, 8); + + SendCommand(&c); + + UsbCommand resp; + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + int recv_len = resp.arg[0]; + uint8_t *recv = resp.d.asBytes; + if (recv_len == 0) { + PrintAndLog("Received SOF only. Maybe Picopass/iCLASS?"); + } else if (recv_len == -1) { + PrintAndLog("Tag didn't respond"); + } else if (recv_len == -2) { + PrintAndLog("Receive buffer overflow"); + } else if (ISO15693_CRC_CHECK != Crc(recv, recv_len)) { + PrintAndLog("CRC check failed on Tag response"); + } else if (!(recv[0] & ISO15693_RES_ERROR)) { + PrintAndLog("Tag returned OK"); + } else { + PrintAndLog("Tag returned Error %i: %s", recv[1], TagErrorStr(recv[1])); + } + } else { + PrintAndLog("No answer from Proxmark"); + } + + if (!getUID(newUid)) { + PrintAndLog("Can't get new UID."); + return 1; + } - SendCommand(&c); - - for (int i=0; i<4; i++) { - if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) { - recv = resp.d.asBytes; - PrintAndLog("received %i octets",resp.arg[0]); - hexout = (char *)malloc(resp.arg[0] * 3 + 1); - if (hexout != NULL) { - for (int i = 0; i < resp.arg[0]; i++) { // data in hex - sprintf(&hexout[i * 3], "%02X ", recv[i]); - } - PrintAndLog("%s", hexout); - free(hexout); - } - } else { - PrintAndLog("timeout while waiting for reply."); - } - } - - if (!getUID(newUid)) { - PrintAndLog("Can't get new UID."); - return 1; - } - - PrintAndLog(""); - PrintAndLog("old UID : %02X %02X %02X %02X %02X %02X %02X %02X", oldUid[7], oldUid[6], oldUid[5], oldUid[4], oldUid[3], oldUid[2], oldUid[1], oldUid[0]); - PrintAndLog("new UID : %02X %02X %02X %02X %02X %02X %02X %02X", newUid[7], newUid[6], newUid[5], newUid[4], newUid[3], newUid[2], newUid[1], newUid[0]); - return 0; + PrintAndLog(""); + PrintAndLog("old UID : %02X %02X %02X %02X %02X %02X %02X %02X", oldUid[7], oldUid[6], oldUid[5], oldUid[4], oldUid[3], oldUid[2], oldUid[1], oldUid[0]); + PrintAndLog("new UID : %02X %02X %02X %02X %02X %02X %02X %02X", newUid[7], newUid[6], newUid[5], newUid[4], newUid[3], newUid[2], newUid[1], newUid[0]); + return 0; } -static command_t CommandTable15Cmd[] = -{ - {"help", CmdHF15CmdHelp, 1, "This Help"}, - {"inquiry", CmdHF15CmdInquiry, 0, "Search for tags in range"}, +// "HF 15 Cmd" Interface +// Allows direct communication with the tag on command level + +static int CmdHF15CmdHelp(const char*Cmd); + +static command_t CommandTable15Cmd[] = { + {"help", CmdHF15CmdHelp, 1, "This Help"}, + {"inquiry", CmdHF15CmdInquiry, 0, "Search for tags in range"}, /* - {"select", CmdHF15CmdSelect, 0, "Select an tag with a specific UID for further commands"}, + {"select", CmdHF15CmdSelect, 0, "Select an tag with a specific UID for further commands"}, */ - {"read", CmdHF15CmdRead, 0, "Read a block"}, - {"write", CmdHF15CmdWrite, 0, "Write a block"}, - {"readmulti",CmdHF15CmdReadmulti, 0, "Reads multiple Blocks"}, - {"sysinfo",CmdHF15CmdSysinfo, 0, "Get Card Information"}, - {"raw", CmdHF15CmdRaw, 0, "Send raw hex data to tag"}, - {"csetuid", CmdHF15CSetUID, 0, "Set UID for magic Chinese card"}, - {"debug", CmdHF15CmdDebug, 0, "Turn debugging on/off"}, - {NULL, NULL, 0, NULL} + {"read", CmdHF15CmdRead, 0, "Read a block"}, + {"write", CmdHF15CmdWrite, 0, "Write a block"}, + {"readmulti", CmdHF15CmdReadmulti, 0, "Reads multiple Blocks"}, + {"sysinfo", CmdHF15CmdSysinfo, 0, "Get Card Information"}, + {"raw", CmdHF15CmdRaw, 0, "Send raw hex data to tag"}, + {"debug", CmdHF15CmdDebug, 0, "Turn debugging on/off"}, + {NULL, NULL, 0, NULL} }; -int CmdHF15Cmd(const char *Cmd) -{ + +static int CmdHF15Cmd(const char *Cmd) { CmdsParse(CommandTable15Cmd, Cmd); return 0; } - -int CmdHF15CmdHelp(const char *Cmd) -{ + + +static int CmdHF15CmdHelp(const char *Cmd) { CmdsHelp(CommandTable15Cmd); return 0; } + +// "HF 15" interface + +static int CmdHF15Help(const char*Cmd); + +static command_t CommandTable15[] = { + {"help", CmdHF15Help, 1, "This help"}, + {"demod", CmdHF15Demod, 1, "Demodulate ISO15693 from tag"}, + {"read", CmdHF15Read, 0, "Read HF tag (ISO 15693)"}, + {"snoop", CmdHF15Snoop, 0, "Eavesdrop ISO 15693 communications"}, + {"reader", CmdHF15Reader, 0, "Act like an ISO15693 reader"}, + {"sim", CmdHF15Sim, 0, "Fake an ISO15693 tag"}, + {"cmd", CmdHF15Cmd, 0, "Send direct commands to ISO15693 tag"}, + {"findafi", CmdHF15Afi, 0, "Brute force AFI of an ISO15693 tag"}, + {"dumpmemory", CmdHF15DumpMem, 0, "Read all memory pages of an ISO15693 tag"}, + {"csetuid", CmdHF15CSetUID, 0, "Set UID for magic Chinese card"}, + {NULL, NULL, 0, NULL} +}; + + +int CmdHF15(const char *Cmd) { + CmdsParse(CommandTable15, Cmd); + return 0; +} + + +static int CmdHF15Help(const char *Cmd) { + CmdsHelp(CommandTable15); + return 0; +} + + diff --git a/client/cmdhf15.h b/client/cmdhf15.h index ddaa4f71..89cbd259 100644 --- a/client/cmdhf15.h +++ b/client/cmdhf15.h @@ -13,17 +13,7 @@ #include -int CmdHF15(const char *Cmd); - -int CmdHF15Demod(const char *Cmd); -int CmdHF15Read(const char *Cmd); -int HF15Reader(const char *Cmd, bool verbose); -int CmdHF15Reader(const char *Cmd); -int CmdHF15Sim(const char *Cmd); -int CmdHF15Record(const char *Cmd); -int CmdHF15Cmd(const char*Cmd); -int CmdHF15CSetUID(const char *Cmd); -int CmdHF15CmdHelp(const char*Cmd); -int CmdHF15Help(const char*Cmd); +extern int CmdHF15(const char *Cmd); +extern int HF15Reader(const char *Cmd, bool verbose); #endif diff --git a/client/cmdhflist.c b/client/cmdhflist.c index ee21945f..c7e3dab8 100644 --- a/client/cmdhflist.c +++ b/client/cmdhflist.c @@ -243,32 +243,34 @@ void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) { } -void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) -{ - switch(cmd[1]){ - // Mandatory Commands, all Tags must support them: - case ISO15693_INVENTORY :snprintf(exp, size, "INVENTORY");return; - case ISO15693_STAYQUIET :snprintf(exp, size, "STAY_QUIET");return; - // Optional Commands, Tags may support them: - case ISO15693_READBLOCK :snprintf(exp, size, "READBLOCK");return; - case ISO15693_WRITEBLOCK :snprintf(exp, size, "WRITEBLOCK");return; - case ISO15693_LOCKBLOCK :snprintf(exp, size, "LOCKBLOCK");return; - case ISO15693_READ_MULTI_BLOCK :snprintf(exp, size, "READ_MULTI_BLOCK");return; - case ISO15693_SELECT :snprintf(exp, size, "SELECT");return; - case ISO15693_RESET_TO_READY :snprintf(exp, size, "RESET_TO_READY");return; - case ISO15693_WRITE_AFI :snprintf(exp, size, "WRITE_AFI");return; - case ISO15693_LOCK_AFI :snprintf(exp, size, "LOCK_AFI");return; - case ISO15693_WRITE_DSFID :snprintf(exp, size, "WRITE_DSFID");return; - case ISO15693_LOCK_DSFID :snprintf(exp, size, "LOCK_DSFID");return; - case ISO15693_GET_SYSTEM_INFO :snprintf(exp, size, "GET_SYSTEM_INFO");return; - case ISO15693_READ_MULTI_SECSTATUS :snprintf(exp, size, "READ_MULTI_SECSTATUS");return; - default: break; - } +void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) { + if (cmdsize >= 2) { + switch (cmd[1]) { + // Mandatory Commands, all Tags must support them: + case ISO15693_INVENTORY :snprintf(exp, size, "INVENTORY");return; + case ISO15693_STAYQUIET :snprintf(exp, size, "STAY_QUIET");return; + // Optional Commands, Tags may support them: + case ISO15693_READBLOCK :snprintf(exp, size, "READBLOCK");return; + case ISO15693_WRITEBLOCK :snprintf(exp, size, "WRITEBLOCK");return; + case ISO15693_LOCKBLOCK :snprintf(exp, size, "LOCKBLOCK");return; + case ISO15693_READ_MULTI_BLOCK :snprintf(exp, size, "READ_MULTI_BLOCK");return; + case ISO15693_WRITE_MULTI_BLOCK :snprintf(exp, size, "WRITE_MULTI_BLOCK");return; + case ISO15693_SELECT :snprintf(exp, size, "SELECT");return; + case ISO15693_RESET_TO_READY :snprintf(exp, size, "RESET_TO_READY");return; + case ISO15693_WRITE_AFI :snprintf(exp, size, "WRITE_AFI");return; + case ISO15693_LOCK_AFI :snprintf(exp, size, "LOCK_AFI");return; + case ISO15693_WRITE_DSFID :snprintf(exp, size, "WRITE_DSFID");return; + case ISO15693_LOCK_DSFID :snprintf(exp, size, "LOCK_DSFID");return; + case ISO15693_GET_SYSTEM_INFO :snprintf(exp, size, "GET_SYSTEM_INFO");return; + case ISO15693_READ_MULTI_SECSTATUS :snprintf(exp, size, "READ_MULTI_SECSTATUS");return; + default: break; + } - if (cmd[1] > ISO15693_STAYQUIET && cmd[1] < ISO15693_READBLOCK) snprintf(exp, size, "Mandatory RFU"); - else if (cmd[1] > ISO15693_READ_MULTI_SECSTATUS && cmd[1] <= 0x9F) snprintf(exp, size, "Optional RFU"); - else if ( cmd[1] >= 0xA0 && cmd[1] <= 0xDF ) snprintf(exp, size, "Custom command"); - else if ( cmd[1] >= 0xE0 && cmd[1] <= 0xFF ) snprintf(exp, size, "Proprietary command"); + if (cmd[1] > ISO15693_STAYQUIET && cmd[1] < ISO15693_READBLOCK) snprintf(exp, size, "Mandatory RFU"); + else if (cmd[1] > ISO15693_READ_MULTI_SECSTATUS && cmd[1] <= 0x9F) snprintf(exp, size, "Optional RFU"); + else if ( cmd[1] >= 0xA0 && cmd[1] <= 0xDF ) snprintf(exp, size, "Custom command"); + else if ( cmd[1] >= 0xE0 && cmd[1] <= 0xFF ) snprintf(exp, size, "Proprietary command"); + } } @@ -969,6 +971,8 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui if (data_len == 0) { if (protocol == ICLASS && duration == 2048) { sprintf(line[0], " "); + } else if (protocol == ISO_15693 && duration == 512) { + sprintf(line[0], " "); } else { sprintf(line[0], " "); } diff --git a/common/protocols.h b/common/protocols.h index 9a854363..37a88449 100644 --- a/common/protocols.h +++ b/common/protocols.h @@ -187,6 +187,7 @@ NXP/Philips CUSTOM COMMANDS #define ISO15693_WRITEBLOCK 0x21 #define ISO15693_LOCKBLOCK 0x22 #define ISO15693_READ_MULTI_BLOCK 0x23 +#define ISO15693_WRITE_MULTI_BLOCK 0x24 #define ISO15693_SELECT 0x25 #define ISO15693_RESET_TO_READY 0x26 #define ISO15693_WRITE_AFI 0x27