X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/a287e8cfdd5798364eb1b870f63b1ee3141d881b..76a608af8e342b50718cfd0e53c0fa932304dbd9:/armsrc/iclass.c diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 42deea86..f5e821cb 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -36,11 +36,7 @@ // //----------------------------------------------------------------------------- -#include "proxmark3.h" #include "apps.h" -#include "util.h" -#include "string.h" -#include "common.h" #include "cmd.h" // Needed for CRC in emulation mode; // same construction as in ISO 14443; @@ -52,7 +48,6 @@ static int timeout = 4096; - static int SendIClassAnswer(uint8_t *resp, int respLen, int delay); //----------------------------------------------------------------------------- @@ -63,7 +58,7 @@ static struct { enum { STATE_UNSYNCD, STATE_START_OF_COMMUNICATION, - STATE_RECEIVING + STATE_RECEIVING } state; uint16_t shiftReg; int bitCnt; @@ -425,6 +420,7 @@ static RAMFUNC int ManchesterDecoding(int v) if(!(Demod.buffer2 & Demod.syncBit) || !(Demod.buffer3 & Demod.syncBit)) { Demod.state = DEMOD_UNSYNCD; error = 0x88; + return FALSE; } // TODO: use this error value to print? Ask Holiman. @@ -1294,7 +1290,7 @@ int doIClassSimulation( int simulationMode, uint8_t *reader_mac_buf) else { //#db# Unknown command received from reader (len=5): 26 1 0 f6 a 44 44 44 44 // Never seen this command before - Dbprintf("Unknown command received from reader (len=%d): %x %x %x %x %x %x %x %x %x", + Dbprintf("Unhandled command received from reader (len=%d): %x %x %x %x %x %x %x %x %x", len, receivedCmd[0], receivedCmd[1], receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5], @@ -1467,7 +1463,7 @@ void CodeIClassCommand(const uint8_t * cmd, int len) for(j = 0; j < 4; j++) { for(k = 0; k < 4; k++) { if(k == (b & 3)) { - ToSend[++ToSendMax] = 0x0f; + ToSend[++ToSendMax] = 0xf0; } else { ToSend[++ToSendMax] = 0x00; @@ -1986,18 +1982,26 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks) { } bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data) { - uint8_t write[] = { ICLASS_CMD_UPDATE, blockNo, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t write[] = { ICLASS_CMD_UPDATE, blockNo, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //uint8_t readblockdata[10]; //write[1] = blockNo; memcpy(write+2, data, 12); // data + mac + char *wrCmd = (char *)(write+1); + uint16_t wrCrc = iclass_crc16(wrCmd, 13); + write[14] = wrCrc >> 8; + write[15] = wrCrc & 0xff; uint8_t resp[] = {0,0,0,0,0,0,0,0,0,0}; - bool isOK; + bool isOK = false; + isOK = sendCmdGetResponseWithRetries(write,sizeof(write),resp,sizeof(resp),10); - if (isOK) { + if (isOK) { //if reader responded correctly //Dbprintf("WriteResp: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",resp[0],resp[1],resp[2],resp[3],resp[4],resp[5],resp[6],resp[7],resp[8],resp[9]); - if (memcmp(write+2,resp,8)) { + if (memcmp(write+2,resp,8)) { //if response is not equal to write values + if (blockNo != 3 && blockNo != 4) { //if not programming key areas (note key blocks don't get programmed with actual key data it is xor data) //error try again isOK = sendCmdGetResponseWithRetries(write,sizeof(write),resp,sizeof(resp),10); + } + } } return isOK;