X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/9455b51c2a0554ea2bd55a28dee5a5c2a6707fc6..149aeadaa609b01db86ba3b4ee23b317f16bede5:/armsrc/iso15693.c diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 7f4cbf8a..d8bec898 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -1,7 +1,7 @@ //----------------------------------------------------------------------------- // Jonathan Westhues, split Nov 2006 // Modified by Greg Jones, Jan 2009 -// Modified by Adrian Dabrowski "atrox", Mar-Sept 2010 +// Modified by Adrian Dabrowski "atrox", Mar-Sept 2010,Oct 2011 // // This code is licensed to you under the terms of the GNU GPL, version 2 or, // at your option, any later version. See the LICENSE.txt file for the text of @@ -51,18 +51,21 @@ // *) signal decoding from the card is still a bit shaky. // *) signal decoding is unable to detect collissions. // *) add anti-collission support for inventory-commands +// *) read security status of a block // *) sniffing and simulation do only support one transmission mode. need to support // all 8 transmission combinations // *) remove or refactor code under "depricated" // *) document all the functions -#include "proxmark3.h" +#include "../include/proxmark3.h" #include "util.h" #include "apps.h" #include "string.h" -#include "iso15693tools.h" - +#include "../common/iso15693tools.h" +#include "../common/cmd.h" +#include "crapto1.h" +#include "mifareutil.h" #define arraylen(x) (sizeof(x)/sizeof((x)[0])) @@ -599,12 +602,13 @@ static void BuildIdentifyRequest(void); //----------------------------------------------------------------------------- void AcquireRawAdcSamplesIso15693(void) { + uint8_t *dest = mifare_get_bigbufptr(); + int c = 0; - uint8_t *dest = (uint8_t *)BigBuf; int getNext = 0; - int8_t prev = 0; + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); BuildIdentifyRequest(); SetAdcMuxFor(GPIO_MUXSEL_HIPKD); @@ -680,18 +684,19 @@ void AcquireRawAdcSamplesIso15693(void) void RecordRawAdcSamplesIso15693(void) { + uint8_t *dest = mifare_get_bigbufptr(); + int c = 0; - uint8_t *dest = (uint8_t *)BigBuf; int getNext = 0; - int8_t prev = 0; + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); // Setup SSC FpgaSetupSsc(); // Start from off (no field generated) - FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - SpinDelay(200); + FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); + SpinDelay(200); SetAdcMuxFor(GPIO_MUXSEL_HIPKD); @@ -745,25 +750,27 @@ void RecordRawAdcSamplesIso15693(void) // Initialize the proxmark as iso15k reader +// (this might produces glitches that confuse some tags void Iso15693InitReader() { LED_A_ON(); LED_B_ON(); LED_C_OFF(); LED_D_OFF(); + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); // Setup SSC - FpgaSetupSsc(); + // FpgaSetupSsc(); // Start from off (no field generated) FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); - SpinDelay(200); + SpinDelay(10); SetAdcMuxFor(GPIO_MUXSEL_HIPKD); FpgaSetupSsc(); // Give the tags time to energize FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR); - SpinDelay(200); + SpinDelay(250); LED_A_ON(); LED_B_OFF(); @@ -857,7 +864,7 @@ static void BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber ) CodeIso15693AsReader(cmd, sizeof(cmd)); } -// Universal Method for sending to and recv from a tag +// Universal Method for sending to and recv bytes from a tag // init ... should we initialize the reader? // speed ... 0 low speed, 1 hi speed // **recv will return you a pointer to the received data @@ -1013,6 +1020,7 @@ void ReaderIso15693(uint32_t parameter) // Blank arrays memset(BigBuf + 3660, 0, 300); + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); // Setup SSC FpgaSetupSsc(); @@ -1039,7 +1047,7 @@ void ReaderIso15693(uint32_t parameter) // FIRST WE RUN AN INVENTORY TO GET THE TAG UID // THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME - uint8_t TagUID[8]; // where we hold the uid for hi15reader + uint8_t TagUID[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // where we hold the uid for hi15reader // BuildIdentifyRequest(); // //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait); @@ -1100,7 +1108,7 @@ void ReaderIso15693(uint32_t parameter) Dbprintf("%d octets read from IDENTIFY request:", answerLen1); DbdecodeIso15693Answer(answerLen1,answer1); - Dbhexdump(answerLen1,answer1); + Dbhexdump(answerLen1,answer1,true); // UID is reverse if (answerLen1>=12) @@ -1111,11 +1119,11 @@ void ReaderIso15693(uint32_t parameter) Dbprintf("%d octets read from SELECT request:", answerLen2); DbdecodeIso15693Answer(answerLen2,answer2); - Dbhexdump(answerLen2,answer2); + Dbhexdump(answerLen2,answer2,true); Dbprintf("%d octets read from XXX request:", answerLen3); DbdecodeIso15693Answer(answerLen3,answer3); - Dbhexdump(answerLen3,answer3); + Dbhexdump(answerLen3,answer3,true); // read all pages @@ -1128,7 +1136,7 @@ void ReaderIso15693(uint32_t parameter) if (answerLen2>0) { Dbprintf("READ SINGLE BLOCK %d returned %d octets:",i,answerLen2); DbdecodeIso15693Answer(answerLen2,answer2); - Dbhexdump(answerLen2,answer2); + Dbhexdump(answerLen2,answer2,true); if ( *((uint32_t*) answer2) == 0x07160101 ) break; // exit on NoPageErr } i++; @@ -1163,6 +1171,7 @@ void SimTagIso15693(uint32_t parameter) // Blank arrays memset(answer1, 0, 100); + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); // Setup SSC FpgaSetupSsc(); @@ -1258,27 +1267,24 @@ void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8 int recvlen=0; uint8_t *recvbuf=(uint8_t *)BigBuf; - UsbCommand n; +// UsbCommand n; if (DEBUG) { Dbprintf("SEND"); - Dbhexdump(datalen,data); + Dbhexdump(datalen,data,true); } recvlen=SendDataTag(data,datalen,1,speed,(recv?&recvbuf:NULL)); if (recv) { - n.cmd=/* CMD_ISO_15693_COMMAND_DONE */ CMD_ACK; - n.arg[0]=recvlen>48?48:recvlen; - memcpy(n.d.asBytes, recvbuf, 48); LED_B_ON(); - UsbSendPacket((uint8_t *)&n, sizeof(n)); + cmd_send(CMD_ACK,recvlen>48?48:recvlen,0,0,recvbuf,48); LED_B_OFF(); if (DEBUG) { Dbprintf("RECV"); DbdecodeIso15693Answer(recvlen,recvbuf); - Dbhexdump(recvlen,recvbuf); + Dbhexdump(recvlen,recvbuf,true); } } @@ -1291,6 +1297,7 @@ void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8 // -- Misc & deprecated functions // -------------------------------------------------------------------- +/* // do not use; has a fix UID static void __attribute__((unused)) BuildSysInfoRequest(uint8_t *uid) @@ -1322,47 +1329,6 @@ static void __attribute__((unused)) BuildSysInfoRequest(uint8_t *uid) CodeIso15693AsReader(cmd, sizeof(cmd)); } -// do not use; has a fix UID -static void __attribute__((unused)) BuildSelectRequest( uint8_t uid[]) -{ - -// uid[6]=0x31; // this is getting ignored - the uid array is not happening... - uint8_t cmd[12]; - - uint16_t crc; - // one sub-carrier, inventory, 1 slot, fast rate - //cmd[0] = (1 << 2) | (1 << 5) | (1 << 1); // INVENTROY FLAGS - cmd[0] = (1 << 4) | (1 << 5) | (1 << 1); // Select and addressed FLAGS - // SELECT command code - cmd[1] = 0x25; - // 64-bit UID -// cmd[2] = uid[0];//0x32; -// cmd[3]= uid[1];//0x4b; -// cmd[4] = uid[2];//0x03; -// cmd[5] = uid[3];//0x01; -// cmd[6] = uid[4];//0x00; -// cmd[7] = uid[5];//0x10; -// cmd[8] = uid[6];//0x05; - cmd[2] = 0x32;// - cmd[3] = 0x4b; - cmd[4] = 0x03; - cmd[5] = 0x01; - cmd[6] = 0x00; - cmd[7] = 0x10; - cmd[8] = 0x05; // infineon? - - cmd[9]= 0xe0; // always e0 (not exactly unique) - -// DbpIntegers(cmd[8],cmd[7],cmd[6]); - // Now the CRC - crc = Crc(cmd, 10); // the crc needs to be calculated over 10 bytes - cmd[10] = crc & 0xff; - cmd[11] = crc >> 8; - - CodeIso15693AsReader(cmd, sizeof(cmd)); -} - - // do not use; has a fix UID static void __attribute__((unused)) BuildReadMultiBlockRequest(uint8_t *uid) @@ -1471,6 +1437,6 @@ static void __attribute__((unused)) BuildArbitraryCustomRequest(uint8_t uid[], u - +*/