From: iceman1001 Date: Thu, 29 Jan 2015 20:39:33 +0000 (+0100) Subject: Merge branch 'master' of https://github.com/Proxmark/proxmark3 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/64d1b4efc932898dc250dbc5d8f7418e3643b27b Merge branch 'master' of https://github.com/Proxmark/proxmark3 Conflicts: armsrc/Makefile armsrc/appmain.c armsrc/apps.h armsrc/epa.c armsrc/iclass.c armsrc/iso14443a.c armsrc/iso14443a.h armsrc/iso15693.c armsrc/lfops.c armsrc/mifarecmd.c armsrc/mifareutil.c armsrc/mifareutil.h armsrc/string.h armsrc/util.h bootrom/bootrom.c client/Makefile client/cmddata.c client/cmddata.h client/cmdhf.c client/cmdhf14a.c client/cmdhf14b.c client/cmdhf15.c client/cmdhficlass.c client/cmdhfmf.c client/cmdhfmfu.c client/cmdlf.c client/cmdlfem4x.c client/cmdlfhid.c client/cmdlfhitag.c client/cmdlfio.c client/cmdmain.c client/data.h client/flash.c client/graph.c client/graph.h client/loclass/elite_crack.c client/loclass/fileutils.c client/lualibs/commands.lua client/lualibs/html_dumplib.lua client/lualibs/mf_default_keys.lua client/lualibs/utils.lua client/mifarehost.c client/nonce2key/crapto1.c client/proxmark3.c client/scripting.c client/scripts/tnp3dump.lua client/scripts/tnp3sim.lua client/scripts/tracetest.lua common/Makefile.common common/cmd.c common/cmd.h common/lfdemod.c common/lfdemod.h common/usb_cdc.c common/usb_cdc.h include/usb_cmd.h --- 64d1b4efc932898dc250dbc5d8f7418e3643b27b diff --cc armsrc/Makefile index 69e4738a,bbcbcb1c..52317165 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@@ -41,9 -41,9 +41,10 @@@ ARMSRC = fpgaloader.c $(SRC_CRAPTO1) \ $(SRC_CRC) \ legic_prng.c \ - iclass.c + iclass.c \ + BigBuf.c \ + # stdint.h provided locally until GCC 4.5 becomes C99 compliant APP_CFLAGS += -I. diff --cc armsrc/appmain.c index c158ad2c,791ad4f8..00e9ba4d --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@@ -811,11 -805,11 +808,11 @@@ void UsbPacketReceived(uint8_t *packet MifareUC_Auth2(c->arg[0],c->d.asBytes); break; case CMD_MIFAREU_READCARD: - MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes); + MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes); - break; + break; case CMD_MIFAREUC_READCARD: - MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes); - break; + MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes); + break; case CMD_MIFARE_READSC: MifareReadSector(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes); break; diff --cc armsrc/apps.h index 30010f1b,5ef87623..39ee3211 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@@ -14,44 -14,13 +14,14 @@@ #include #include -#include "common.h" -#include "hitag2.h" -#include "mifare.h" +#include +#include +#include +#include - - #include "../include/common.h" - #include "../include/hitag2.h" - #include "../include/mifare.h" - - //#include - //#include - //#include "des.h" - //#include "aes.h" - #include "../common/desfire.h" #include "../common/crc32.h" - - // The large multi-purpose buffer, typically used to hold A/D samples, - // maybe processed in some way. - #define BIGBUF_SIZE 40000 - uint32_t BigBuf[BIGBUF_SIZE / sizeof(uint32_t)]; - #define TRACE_OFFSET 0 - #define TRACE_SIZE 3000 - #define RECV_CMD_OFFSET (TRACE_OFFSET + TRACE_SIZE) - #define MAX_FRAME_SIZE 256 - #define MAX_PARITY_SIZE ((MAX_FRAME_SIZE + 1)/ 8) - #define RECV_CMD_PAR_OFFSET (RECV_CMD_OFFSET + MAX_FRAME_SIZE) - #define RECV_RESP_OFFSET (RECV_CMD_PAR_OFFSET + MAX_PARITY_SIZE) - #define RECV_RESP_PAR_OFFSET (RECV_RESP_OFFSET + MAX_FRAME_SIZE) - #define CARD_MEMORY_OFFSET (RECV_RESP_PAR_OFFSET + MAX_PARITY_SIZE) - #define CARD_MEMORY_SIZE 4096 - #define DMA_BUFFER_OFFSET CARD_MEMORY_OFFSET - #define DMA_BUFFER_SIZE CARD_MEMORY_SIZE - #define FREE_BUFFER_OFFSET (CARD_MEMORY_OFFSET + CARD_MEMORY_SIZE) - #define FREE_BUFFER_SIZE (BIGBUF_SIZE - FREE_BUFFER_OFFSET - 1) + #include "BigBuf.h" extern const uint8_t OddByteParity[256]; - extern uint8_t *trace; // = (uint8_t *) BigBuf; - extern int traceLen; // = 0; extern int rsamples; // = 0; extern int tracing; // = TRUE; extern uint8_t trigger; @@@ -76,13 -45,9 +46,12 @@@ void ToSendReset(void) void ListenReaderField(int limit); void AcquireRawAdcSamples125k(int at134khz); void SnoopLFRawAdcSamples(int divisor, int trigger_threshold); -void DoAcquisition125k(int trigger_threshold); +void DoAcquisition125k_internal(int trigger_threshold, bool silent); +void DoAcquisition125k_threshold(int trigger_threshold); +void DoAcquisition125k(); + extern int ToSendMax; extern uint8_t ToSend[]; - extern uint32_t BigBuf[]; /// fpga.h void FpgaSendCommand(uint16_t cmd, uint16_t v); diff --cc armsrc/epa.c index 0bbd2dd7,bec79e61..a04b7628 --- a/armsrc/epa.c +++ b/armsrc/epa.c @@@ -432,9 -425,9 +432,11 @@@ int EPA_Setup( // power up the field iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD); - + + iso14a_set_timeout(10500); + + iso14a_set_timeout(10500); + // select the card return_code = iso14443a_select_card(uid, &card_select_info, NULL); if (return_code != 1) { diff --cc armsrc/iclass.c index aca2c918,1a375118..c0edc1e0 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@@ -642,21 -640,25 +642,25 @@@ void RAMFUNC SnoopIClass(void // The command (reader -> tag) that we're receiving. // The length of a received command will in most cases be no more than 18 bytes. // So 32 should be enough! - uint8_t *readerToTagCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET); + #define ICLASS_BUFFER_SIZE 32 + uint8_t readerToTagCmd[ICLASS_BUFFER_SIZE]; // The response (tag -> reader) that we're receiving. - uint8_t *tagToReaderResponse = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET); - + uint8_t tagToReaderResponse[ICLASS_BUFFER_SIZE]; + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); + // free all BigBuf memory + BigBuf_free(); + // The DMA buffer, used to stream samples from the FPGA + uint8_t *dmaBuf = BigBuf_malloc(DMA_BUFFER_SIZE); + - // reset traceLen to 0 + // reset traceLen to 0 iso14a_set_tracing(TRUE); iso14a_clear_trace(); iso14a_set_trigger(FALSE); - // The DMA buffer, used to stream samples from the FPGA - int8_t *dmaBuf = ((int8_t *)BigBuf) + DMA_BUFFER_OFFSET; - int lastRxCounter; + int lastRxCounter; - int8_t *upTo; + uint8_t *upTo; int smpl; int maxBehindBy = 0; @@@ -765,16 -771,17 +773,17 @@@ if(div > 3) { smpl = decbyte; if(ManchesterDecoding(smpl & 0x0F)) { + time_stop = (GetCountSspClk()-time_0) << 4; + - rsamples = samples - Demod.samples; + rsamples = samples - Demod.samples; LED_B_ON(); - if(tracing) { + if(tracing) { uint8_t parity[MAX_PARITY_SIZE]; GetParity(Demod.output, Demod.len, parity); - LogTrace(Demod.output, Demod.len, (GetCountSspClk()-time_0) << 4, (GetCountSspClk()-time_0) << 4, parity, FALSE); + LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE); } - // And ready to receive another response. memset(&Demod, 0, sizeof(Demod)); Demod.output = tagToReaderResponse; @@@ -865,44 -937,17 +939,17 @@@ static void CodeIClassTagAnswer(const u ToSendReset(); // Send SOF - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0xff;//Proxtoair duration starts here - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0xff; + ToSend[++ToSendMax] = 0x1D; for(i = 0; i < len; i++) { - int j; uint8_t b = cmd[i]; - - // Data bits - for(j = 0; j < 8; j++) { - if(b & 1) { - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0xff; - } else { - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0x00; + ToSend[++ToSendMax] = encode4Bits(b & 0xF); //Least significant half + ToSend[++ToSendMax] = encode4Bits((b >>4) & 0xF);//Most significant half - } + } - b >>= 1; - } - } // Send EOF - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0xff; - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0x00; - ToSend[++ToSendMax] = 0x00; - + ToSend[++ToSendMax] = 0xB8; //lastProxToAirDuration = 8*ToSendMax - 3*8 - 3*8;//Not counting zeroes in the beginning or end - // Convert from last byte pos to length ToSendMax++; } @@@ -1267,18 -1309,18 +1311,18 @@@ static void TransmitIClassCommand(cons if (wait) { if(*wait < 10) *wait = 10; - + - for(c = 0; c < *wait;) { - if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { - AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing! - c++; - } - if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { - volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR; - (void)r; - } - WDT_HIT(); - } + for(c = 0; c < *wait;) { + if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) { + AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing! + c++; + } + if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) { + volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR; + (void)r; + } + WDT_HIT(); + } } @@@ -1361,19 -1403,19 +1405,19 @@@ void CodeIClassCommand(const uint8_t * void ReaderTransmitIClass(uint8_t* frame, int len) { - int wait = 0; - int samples = 0; + int wait = 0; + int samples = 0; - // This is tied to other size changes - CodeIClassCommand(frame,len); + // This is tied to other size changes + CodeIClassCommand(frame,len); - // Select the card - TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait); - if(trigger) - LED_A_ON(); + // Select the card + TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait); + if(trigger) + LED_A_ON(); - // Store reader command in buffer + // Store reader command in buffer - if (tracing) { + if (tracing) { uint8_t par[MAX_PARITY_SIZE]; GetParity(frame, len, par); LogTrace(frame, len, rsamples, rsamples, par, TRUE); diff --cc armsrc/mifarecmd.c index 7a33afbb,4279e63f..50a5634d --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@@ -1190,4 -1183,4 +1183,4 @@@ void Mifare_DES_Auth2(uint32_t arg0, ui cmd_send(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout)); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); LEDsoff(); --} ++} diff --cc armsrc/mifareutil.c index 18598191,f79c2ede..c3ba1b81 --- a/armsrc/mifareutil.c +++ b/armsrc/mifareutil.c @@@ -76,26 -65,26 +65,26 @@@ uint8_t mf_crypto1_encrypt4bit(struct C } // send commands - int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) + int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing) { -- return mifare_sendcmd_shortex(pcs, crypted, cmd, data, answer, answer_parity, timing); --} -- --int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing) --{ -- uint8_t dcmd[8]; - dcmd[0] = cmd; - dcmd[0] = cmd; - dcmd[1] = data[0]; - dcmd[2] = data[1]; - dcmd[3] = data[2]; - dcmd[4] = data[3]; - dcmd[5] = data[4]; - AppendCrc14443a(dcmd, 6); - ReaderTransmit(dcmd, sizeof(dcmd), NULL); - int len = ReaderReceive(answer, answer_parity); - if(!len) { - if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout."); - return 2; ++ return mifare_sendcmd_shortex(pcs, crypted, cmd, data, answer, answer_parity, timing); ++} ++ ++int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing) ++{ ++ uint8_t dcmd[8]; ++ dcmd[0] = cmd; + dcmd[1] = data[0]; - dcmd[2] = data[1]; ++ dcmd[2] = data[1]; + dcmd[3] = data[2]; + dcmd[4] = data[3]; + dcmd[5] = data[4]; - AppendCrc14443a(dcmd, 6); - ReaderTransmit(dcmd, sizeof(dcmd), NULL); - int len = ReaderReceive(answer, answer_parity); - if(!len) { - if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout."); - return 2; ++ AppendCrc14443a(dcmd, 6); ++ ReaderTransmit(dcmd, sizeof(dcmd), NULL); ++ int len = ReaderReceive(answer, answer_parity); ++ if(!len) { ++ if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout."); ++ return 2; } return len; } @@@ -117,13 -106,13 +106,13 @@@ int mifare_sendcmd_short_mfucauth(struc if(len==1) { if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("NAK - Authentication failed."); return 1; -- } -- return len; --} -- --int mifare_sendcmd_shortex(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) --{ -- uint8_t dcmd[4], ecmd[4]; ++ } ++ return len; ++} ++ ++int mifare_sendcmd_shortex(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) ++{ ++ uint8_t dcmd[4], ecmd[4]; uint16_t pos, res; uint8_t par[1]; // 1 Byte parity is enough here dcmd[0] = cmd; @@@ -295,9 -284,9 +284,9 @@@ int mifare_classic_readblock(struct Cry } memcpy(blockData, receivedAnswer, 16); -- return 0; -} - ++ return 0; +} + // mifare ultralight commands int mifare_ultra_auth1(uint32_t uid, uint8_t *blockData){ @@@ -347,45 -336,45 +336,45 @@@ int mifare_ultra_auth2(uint32_t uid, ui } memcpy(blockData, receivedAnswer, 11); return 0; - } - - int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) - { - uint16_t len; - uint8_t bt[2]; - uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf(); - uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE; - - - // command MIFARE_CLASSIC_READBLOCK - len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL); - if (len == 1) { + } + -int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) -{ - uint16_t len; - uint8_t bt[2]; ++int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) ++{ ++ uint16_t len; ++ uint8_t bt[2]; + uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE]; + uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE]; - + - // command MIFARE_CLASSIC_READBLOCK - len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL); - if (len == 1) { ++ ++ // command MIFARE_CLASSIC_READBLOCK ++ len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL); ++ if (len == 1) { if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("Cmd Error: %02x", receivedAnswer[0]); -- return 1; -- } -- if (len != 18) { ++ Dbprintf("Cmd Error: %02x", receivedAnswer[0]); ++ return 1; ++ } ++ if (len != 18) { if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("Cmd Error: card timeout. len: %x", len); -- return 2; -- } -- -- memcpy(bt, receivedAnswer + 16, 2); -- AppendCrc14443a(receivedAnswer, 16); -- if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) { ++ Dbprintf("Cmd Error: card timeout. len: %x", len); ++ return 2; ++ } ++ ++ memcpy(bt, receivedAnswer + 16, 2); ++ AppendCrc14443a(receivedAnswer, 16); ++ if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) { if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("Cmd CRC response error."); -- return 3; -- } -- -- memcpy(blockData, receivedAnswer, 14); -- return 0; --} -- -- --int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) --{ -- // variables ++ Dbprintf("Cmd CRC response error."); ++ return 3; ++ } ++ ++ memcpy(blockData, receivedAnswer, 14); ++ return 0; ++} ++ ++ ++int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) ++{ ++ // variables uint16_t len, i; uint32_t pos; uint8_t par[3] = {0}; // enough for 18 Bytes to send @@@ -427,68 -416,68 +416,68 @@@ return 2; } -- return 0; --} -- --int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) --{ - uint16_t len; - uint8_t par[3] = {0}; // enough for 18 parity bits - uint16_t len; - uint8_t par[3] = {0}; // enough for 18 parity bits -- uint8_t d_block[18] = {0x00}; - uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf(); - uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE; - - // command MIFARE_CLASSIC_WRITEBLOCK - len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL); - - if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK ++ return 0; ++} ++ ++int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) ++{ ++ uint16_t len; ++ uint8_t par[3] = {0}; // enough for 18 parity bits ++ uint8_t d_block[18] = {0x00}; + uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE]; + uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE]; - - // command MIFARE_CLASSIC_WRITEBLOCK - len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL); - - if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK ++ ++ // command MIFARE_CLASSIC_WRITEBLOCK ++ len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL); ++ ++ if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]); - return 1; - } - return 1; - } -- -- memcpy(d_block, blockData, 16); -- AppendCrc14443a(d_block, 16); -- -- ReaderTransmitPar(d_block, sizeof(d_block), par, NULL); - - -- len = ReaderReceive(receivedAnswer, receivedAnswerPar); -- -- if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK ++ Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]); ++ return 1; ++ } ++ ++ memcpy(d_block, blockData, 16); ++ AppendCrc14443a(d_block, 16); ++ ++ ReaderTransmitPar(d_block, sizeof(d_block), par, NULL); ++ ++ len = ReaderReceive(receivedAnswer, receivedAnswerPar); ++ ++ if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len); - return 2; - } - return 2; - } -- return 0; --} -- --int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) --{ -- uint16_t len; -- uint8_t d_block[8] = {0x00}; - uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf(); - uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE; - - // command MIFARE_CLASSIC_WRITEBLOCK - d_block[0]= blockNo; - memcpy(d_block+1,blockData,4); - AppendCrc14443a(d_block, 6); - - len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL); - - if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK ++ Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len); ++ return 2; ++ } ++ return 0; ++} ++ ++int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) ++{ ++ uint16_t len; ++ uint8_t d_block[8] = {0x00}; + uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE]; + uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE]; - - // command MIFARE_CLASSIC_WRITEBLOCK - d_block[0]= blockNo; - memcpy(d_block+1,blockData,4); - AppendCrc14443a(d_block, 6); - - len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL); - - if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK ++ ++ // command MIFARE_CLASSIC_WRITEBLOCK ++ d_block[0]= blockNo; ++ memcpy(d_block+1,blockData,4); ++ AppendCrc14443a(d_block, 6); ++ ++ len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL); ++ ++ if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0],len); - return 1; - } - return 0; - return 1; - } - return 0; --} -- --int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) --{ ++ Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0],len); ++ return 1; ++ } ++ return 0; ++} ++ ++int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) ++{ uint16_t len; - uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf(); - uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE; + uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE]; + uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE]; len = mifare_sendcmd_short(pcs, pcs == NULL ? false:true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL); if (len != 0) { @@@ -497,24 -486,24 +486,24 @@@ return 1; } -- return 0; --} -- --int mifare_ultra_halt(uint32_t uid) --{ - uint16_t len; - uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf(); - uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE; - - len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL); - if (len != 0) { - uint16_t len; ++ return 0; ++} ++ ++int mifare_ultra_halt(uint32_t uid) ++{ ++ uint16_t len; + uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE]; + uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE]; - - len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL); - if (len != 0) { ++ ++ len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL); ++ if (len != 0) { if (MF_DBGLEVEL >= MF_DBG_ERROR) -- Dbprintf("halt error. response len: %x", len); -- return 1; - } - return 0; -} - ++ Dbprintf("halt error. response len: %x", len); ++ return 1; + } - return 0; - } - ++ return 0; ++} ++ // Mifare Memory Structure: up to 32 Sectors with 4 blocks each (1k and 2k cards), // plus evtl. 8 sectors with 16 blocks each (4k cards) @@@ -536,9 -525,9 +525,9 @@@ uint8_t FirstBlockOfSector(uint8_t sect } --// work with emulator memory --void emlSetMem(uint8_t *data, int blockNum, int blocksCount) { - uint8_t* emCARD = get_bigbufptr_emlcardmem(); - uint8_t* emCARD = BigBuf_get_EM_addr(); ++// work with emulator memory ++void emlSetMem(uint8_t *data, int blockNum, int blocksCount) { ++ uint8_t* emCARD = BigBuf_get_EM_addr(); memcpy(emCARD + blockNum * 16, data, blocksCount * 16); } @@@ -717,4 -706,4 +706,4 @@@ int mifare_desfire_des_auth2(uint32_t u return 0; } return 1; --} ++} diff --cc client/lualibs/commands.lua index d2acb3be,a5442f2a..6f309001 --- a/client/lualibs/commands.lua +++ b/client/lualibs/commands.lua @@@ -212,7 -212,7 +212,6 @@@ function Command:getBytes( local data = self.data local cmd = self.cmd local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3 - - return bin.pack("LLLLH",cmd, arg1, arg2, arg3,data); end return _commands diff --cc client/lualibs/html_dumplib.lua index a7890885,3a28d5ae..bd8e6d0c --- a/client/lualibs/html_dumplib.lua +++ b/client/lualibs/html_dumplib.lua @@@ -192,7 -192,7 +192,9 @@@ en return { convert_bin_to_html = convert_bin_to_html, convert_eml_to_html = convert_eml_to_html, - convert_eml_to_bin = convert_eml_to_bin, + convert_eml_to_bin = convert_eml_to_bin, + SaveAsBinary = save_BIN, + SaveAsText = save_TEXT, + SaveAsBinary = save_BIN, + SaveAsText = save_TEXT, } diff --cc client/lualibs/mf_default_keys.lua index 810f0d6e,757112c6..cca4699e --- a/client/lualibs/mf_default_keys.lua +++ b/client/lualibs/mf_default_keys.lua @@@ -158,9 -158,9 +158,23 @@@ local _keys = 'eff603e1efe9', '644672bd4afe', + 'b5ff67cba951', + } + ++ --[[ ++ Kiev metro cards ++ --]] ++ '8fe644038790', ++ 'f14ee7cae863', ++ '632193be1c3c', ++ '569369c5a0e5', ++ '9de89e070277', ++ 'eff603e1efe9', ++ '644672bd4afe', ++ + 'b5ff67cba951', +} + --- -- The keys above have just been pasted in, for completeness sake. They contain duplicates. -- We need to weed the duplicates out before we expose the list to someone who actually wants to use them diff --cc client/mifarehost.c index 3516fca4,7f784850..60dba6c0 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@@ -72,7 -72,7 +72,6 @@@ int mfnested(uint8_t blockNo, uint8_t k uint16_t i, len; uint32_t uid; UsbCommand resp; - - StateList_t statelists[2]; struct Crypto1State *p1, *p2, *p3, *p4; @@@ -250,11 -263,13 +262,13 @@@ int mfCSetBlock(uint8_t blockNo, uint8_ memcpy(c.d.asBytes, data, 16); SendCommand(&c); - UsbCommand resp; + UsbCommand resp; if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { isOK = resp.arg[0] & 0xff; - if (uid != NULL) memcpy(uid, resp.d.asBytes, 4); - if (!isOK) return 2; + if (uid != NULL) + memcpy(uid, resp.d.asBytes, 4); + if (!isOK) + return 2; } else { PrintAndLog("Command execute timeout"); return 1; @@@ -333,16 -351,21 +350,21 @@@ int loadTraceCard(uint8_t *tuid) FillFileNameByUID(traceFileName, tuid, ".eml", 7); f = fopen(traceFileName, "r"); - if (!f) return 1; + if (!f) { + fclose(f); + return 1; + } blockNum = 0; + while(!feof(f)){ + memset(buf, 0, sizeof(buf)); if (fgets(buf, sizeof(buf), f) == NULL) { - PrintAndLog("File reading error."); + PrintAndLog("File reading error."); fclose(f); return 2; - } + } if (strlen(buf) < 32){ if (feof(f)) break; diff --cc client/nonce2key/crapto1.c index c2dd7a54,6c0fcafa..ca926a73 --- a/client/nonce2key/crapto1.c +++ b/client/nonce2key/crapto1.c @@@ -545,10 -545,10 +545,10 @@@ lfsr_common_prefix(uint32_t pfx, uint32 statelist = malloc((sizeof *statelist) << 21); //how large should be? if(!statelist || !odd || !even) { - free(statelist); - free(odd); - free(even); + free(statelist); + free(odd); + free(even); - return 0; + return 0; } s = statelist; diff --cc client/proxmark3.c index 7d50c35a,0e2a698c..c100bbea --- a/client/proxmark3.c +++ b/client/proxmark3.c @@@ -34,9 -34,9 +34,9 @@@ static UsbCommand txcmd volatile static bool txcmd_pending = false; void SendCommand(UsbCommand *c) { - #if 0 + #if 0 - printf("Sending %d bytes\n", sizeof(UsbCommand)); + printf("Sending %d bytes\n", sizeof(UsbCommand)); - #endif + #endif if (offline) { PrintAndLog("Sending bytes to proxmark failed - offline"); @@@ -65,86 -65,86 +65,86 @@@ byte_t rx[0x1000000] byte_t* prx = rx; static void *uart_receiver(void *targ) { - struct receiver_arg *arg = (struct receiver_arg*)targ; - size_t rxlen; - size_t cmd_count; + struct receiver_arg *arg = (struct receiver_arg*)targ; + size_t rxlen; + size_t cmd_count; - + - while (arg->run) { - rxlen = sizeof(UsbCommand); + while (arg->run) { + rxlen = sizeof(UsbCommand); - if (uart_receive(sp,prx,&rxlen)) { + if (uart_receive(sp, prx, &rxlen)) { - prx += rxlen; - if (((prx-rx) % sizeof(UsbCommand)) != 0) { - continue; - } - cmd_count = (prx-rx) / sizeof(UsbCommand); + prx += rxlen; + if (((prx-rx) % sizeof(UsbCommand)) != 0) { + continue; + } + cmd_count = (prx-rx) / sizeof(UsbCommand); - for (size_t i=0; iusb_present == 1) { + if (arg->usb_present == 1) { - rarg.run=1; + rarg.run = 1; - pthread_create(&reader_thread, NULL, &uart_receiver, &rarg); - } + pthread_create(&reader_thread, NULL, &uart_receiver, &rarg); + } - + - FILE *script_file = NULL; + FILE *script_file = NULL; - char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest - + char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest + if (arg->script_cmds_file) { - script_file = fopen(arg->script_cmds_file, "r"); + script_file = fopen(arg->script_cmds_file, "r"); if (script_file) { - printf("using 'scripting' commands file %s\n", arg->script_cmds_file); - } - } + printf("using 'scripting' commands file %s\n", arg->script_cmds_file); + } + } read_history(".history"); while(1) { - // If there is a script file - if (script_file) - { + // If there is a script file + if (script_file) + { if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) { - fclose(script_file); - script_file = NULL; + fclose(script_file); + script_file = NULL; } else { - char *nl; - nl = strrchr(script_cmd_buf, '\r'); - if (nl) *nl = '\0'; + char *nl; + nl = strrchr(script_cmd_buf, '\r'); + if (nl) *nl = '\0'; - nl = strrchr(script_cmd_buf, '\n'); - if (nl) *nl = '\0'; + nl = strrchr(script_cmd_buf, '\n'); + if (nl) *nl = '\0'; - + if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) { - memset(cmd, 0, strlen(script_cmd_buf)); - strcpy(cmd, script_cmd_buf); - printf("%s\n", cmd); - } - } - } + memset(cmd, 0, strlen(script_cmd_buf)); + strcpy(cmd, script_cmd_buf); + printf("%s\n", cmd); + } + } + } if (!script_file) { - cmd = readline(PROXPROMPT); + cmd = readline(PROXPROMPT); } if (cmd) { @@@ -169,19 -169,19 +169,19 @@@ write_history(".history"); - if (arg->usb_present == 1) { - rarg.run = 0; - pthread_join(reader_thread, NULL); - } + if (arg->usb_present == 1) { + rarg.run = 0; + pthread_join(reader_thread, NULL); + } - + if (script_file) { - fclose(script_file); - script_file = NULL; - } + fclose(script_file); + script_file = NULL; + } - + - ExitGraphics(); - pthread_exit(NULL); - return NULL; + ExitGraphics(); + pthread_exit(NULL); + return NULL; } static void dumpAllHelp(int markdown) diff --cc common/Makefile.common index b30294a8,2b2bb2fb..9e8bfdf0 --- a/common/Makefile.common +++ b/common/Makefile.common @@@ -69,8 -69,8 +69,10 @@@ INCLUDES = ../include/proxmark3.h ../in CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n + LIBS = -lgcc + +LIBS = -lgcc + THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC)) ARMOBJ = $(ARMSRC:%.c=$(OBJDIR)/%.o) ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC))