2010-02-21 05:24:25 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-21 08:12:52 +08:00
|
|
|
// Jonathan Westhues, split Nov 2006
|
|
|
|
// Modified by Greg Jones, Jan 2009
|
2012-06-21 01:20:21 +08:00
|
|
|
// Modified by Adrian Dabrowski "atrox", Mar-Sept 2010,Oct 2011
|
2017-09-05 04:48:35 +08:00
|
|
|
// Modified by Christian Herrmann "iceman", 2017
|
2010-02-21 08:12:52 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-02-21 05:24:25 +08:00
|
|
|
// Routines to support ISO 15693. This includes both the reader software and
|
|
|
|
// the `fake tag' modes, but at the moment I've implemented only the reader
|
|
|
|
// stuff, and that barely.
|
2010-02-21 08:12:52 +08:00
|
|
|
// Modified to perform modulation onboard in arm rather than on PC
|
2010-02-21 05:24:25 +08:00
|
|
|
// Also added additional reader commands (SELECT, READ etc.)
|
|
|
|
//-----------------------------------------------------------------------------
|
2010-10-19 22:25:17 +08:00
|
|
|
// The ISO 15693 describes two transmission modes from reader to tag, and 4
|
|
|
|
// transmission modes from tag to reader. As of Mar 2010 this code only
|
|
|
|
// supports one of each: "1of4" mode from reader to tag, and the highspeed
|
|
|
|
// variant with one subcarrier from card to reader.
|
|
|
|
// As long, as the card fully support ISO 15693 this is no problem, since the
|
|
|
|
// reader chooses both data rates, but some non-standard tags do not. Further for
|
|
|
|
// the simulation to work, we will need to support all data rates.
|
|
|
|
//
|
|
|
|
// VCD (reader) -> VICC (tag)
|
|
|
|
// 1 out of 256:
|
|
|
|
// data rate: 1,66 kbit/s (fc/8192)
|
|
|
|
// used for long range
|
|
|
|
// 1 out of 4:
|
|
|
|
// data rate: 26,48 kbit/s (fc/512)
|
|
|
|
// used for short range, high speed
|
|
|
|
//
|
|
|
|
// VICC (tag) -> VCD (reader)
|
|
|
|
// Modulation:
|
|
|
|
// ASK / one subcarrier (423,75 khz)
|
|
|
|
// FSK / two subcarriers (423,75 khz && 484,28 khz)
|
|
|
|
// Data Rates / Modes:
|
|
|
|
// low ASK: 6,62 kbit/s
|
|
|
|
// low FSK: 6.67 kbit/s
|
|
|
|
// high ASK: 26,48 kbit/s
|
|
|
|
// high FSK: 26,69 kbit/s
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// added "1 out of 256" mode (for VCD->PICC) - atrox 20100911
|
|
|
|
|
|
|
|
|
|
|
|
// Random Remarks:
|
|
|
|
// *) UID is always used "transmission order" (LSB), which is reverse to display order
|
|
|
|
|
|
|
|
// TODO / BUGS / ISSUES:
|
|
|
|
// *) writing to tags takes longer: we miss the answer from the tag in most cases
|
|
|
|
// -> tweak the read-timeout times
|
|
|
|
// *) signal decoding from the card is still a bit shaky.
|
|
|
|
// *) signal decoding is unable to detect collissions.
|
|
|
|
// *) add anti-collission support for inventory-commands
|
2012-06-21 01:20:21 +08:00
|
|
|
// *) read security status of a block
|
2010-10-19 22:25:17 +08:00
|
|
|
// *) 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
|
|
|
|
|
2010-02-21 05:57:20 +08:00
|
|
|
#include "proxmark3.h"
|
2010-02-21 06:51:00 +08:00
|
|
|
#include "util.h"
|
2010-02-21 05:24:25 +08:00
|
|
|
#include "apps.h"
|
2010-02-21 08:10:28 +08:00
|
|
|
#include "string.h"
|
2010-10-19 22:25:17 +08:00
|
|
|
#include "iso15693tools.h"
|
2012-12-05 07:39:18 +08:00
|
|
|
#include "cmd.h"
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// ISO 15693 Part 2 - Air Interface
|
|
|
|
// This section basicly contains transmission and receiving of bits
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
// 32 + 2 crc + 1
|
2018-01-29 22:58:00 +08:00
|
|
|
#define ISO15_MAX_FRAME 35
|
|
|
|
#define CMD_ID_RESP 5
|
|
|
|
#define CMD_READ_RESP 13
|
|
|
|
#define CMD_INV_RESP 12
|
2017-09-05 04:48:35 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
#define FrameSOF Iso15693FrameSOF
|
|
|
|
#define Logic0 Iso15693Logic0
|
|
|
|
#define Logic1 Iso15693Logic1
|
|
|
|
#define FrameEOF Iso15693FrameEOF
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
#define Crc(data, len) crc(CRC_15693, (data), (len))
|
|
|
|
#define CheckCrc(data, len) check_crc(CRC_15693, (data), (len))
|
|
|
|
#define AddCrc(data, len) compute_crc(CRC_15693, (data), (len), (data)+(len), (data)+(len)+1)
|
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
#define sprintUID(target,uid) Iso15693sprintUID((target), (uid))
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-09-05 16:10:24 +08:00
|
|
|
static void BuildIdentifyRequest(uint8_t *cmdout);
|
|
|
|
//static void BuildReadBlockRequest(uint8_t *cmdout, uint8_t *uid, uint8_t blockNumber );
|
|
|
|
static void BuildInventoryResponse(uint8_t *cmdout, uint8_t *uid);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// ---------------------------
|
|
|
|
// Signal Processing
|
|
|
|
// ---------------------------
|
|
|
|
|
|
|
|
// prepare data using "1 out of 4" code for later transmission
|
|
|
|
// resulting data rate is 26,48 kbit/s (fc/512)
|
|
|
|
// cmd ... data
|
|
|
|
// n ... length of data
|
2017-08-31 19:24:12 +08:00
|
|
|
static void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
2010-02-21 05:24:25 +08:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
ToSendReset();
|
|
|
|
|
|
|
|
// Give it a bit of slack at the beginning
|
2016-08-05 03:37:43 +08:00
|
|
|
for(i = 0; i < 24; i++)
|
2010-02-21 05:24:25 +08:00
|
|
|
ToSendStuffBit(1);
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// SOF for 1of4
|
2010-02-21 05:24:25 +08:00
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
for(j = 0; j < 8; j += 2) {
|
|
|
|
int these = (cmd[i] >> j) & 3;
|
|
|
|
switch(these) {
|
|
|
|
case 0:
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
// EOF
|
2010-02-21 05:24:25 +08:00
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
|
|
|
|
// And slack at the end, too.
|
2016-08-05 03:37:43 +08:00
|
|
|
for(i = 0; i < 24; i++)
|
2010-02-21 05:24:25 +08:00
|
|
|
ToSendStuffBit(1);
|
|
|
|
}
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// encode data using "1 out of 256" sheme
|
|
|
|
// data rate is 1,66 kbit/s (fc/8192)
|
|
|
|
// is designed for more robust communication over longer distances
|
2017-08-31 19:24:12 +08:00
|
|
|
static void CodeIso15693AsReader256(uint8_t *cmd, int n) {
|
2010-02-21 05:24:25 +08:00
|
|
|
int i, j;
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
ToSendReset();
|
|
|
|
|
|
|
|
// Give it a bit of slack at the beginning
|
2016-08-05 03:37:43 +08:00
|
|
|
for(i = 0; i < 24; i++)
|
2010-10-19 22:25:17 +08:00
|
|
|
ToSendStuffBit(1);
|
|
|
|
|
|
|
|
// SOF for 1of256
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
for(i = 0; i < n; i++) {
|
2016-08-05 03:37:43 +08:00
|
|
|
for (j = 0; j <= 255; j++) {
|
|
|
|
if (cmd[i] == j) {
|
2010-10-19 22:25:17 +08:00
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
2010-02-21 05:24:25 +08:00
|
|
|
} else {
|
2010-10-19 22:25:17 +08:00
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
}
|
|
|
|
}
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
// EOF
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(1);
|
|
|
|
ToSendStuffBit(0);
|
|
|
|
ToSendStuffBit(1);
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// And slack at the end, too.
|
2016-08-05 03:37:43 +08:00
|
|
|
for(i = 0; i < 24; i++)
|
2010-10-19 22:25:17 +08:00
|
|
|
ToSendStuffBit(1);
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transmit the command (to the tag) that was placed in ToSend[].
|
2017-08-31 19:24:12 +08:00
|
|
|
static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait) {
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
int c;
|
2016-04-10 18:58:04 +08:00
|
|
|
volatile uint32_t r;
|
2010-02-21 05:24:25 +08:00
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2017-08-19 15:49:41 +08:00
|
|
|
if (wait) {
|
|
|
|
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)) {
|
|
|
|
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
|
|
|
}
|
|
|
|
WDT_HIT();
|
|
|
|
}
|
|
|
|
}
|
2010-02-21 05:24:25 +08:00
|
|
|
|
|
|
|
c = 0;
|
2018-01-22 01:34:29 +08:00
|
|
|
for(;;) {
|
2017-08-31 19:24:12 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
2010-02-21 05:24:25 +08:00
|
|
|
AT91C_BASE_SSC->SSC_THR = cmd[c];
|
2016-04-10 18:58:04 +08:00
|
|
|
if( ++c >= len) break;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2017-08-19 15:49:41 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
|
|
|
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2018-01-22 01:34:29 +08:00
|
|
|
WDT_HIT();
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2017-08-19 15:49:41 +08:00
|
|
|
if (samples) {
|
|
|
|
if (wait)
|
|
|
|
*samples = (c + *wait) << 3;
|
|
|
|
else
|
|
|
|
*samples = c << 3;
|
|
|
|
}
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Transmit the command (to the reader) that was placed in ToSend[].
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-08-31 19:24:12 +08:00
|
|
|
static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait) {
|
2015-01-05 22:51:27 +08:00
|
|
|
int c = 0;
|
2016-04-10 18:58:04 +08:00
|
|
|
volatile uint32_t r;
|
2015-01-05 22:51:27 +08:00
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR|FPGA_HF_SIMULATOR_MODULATE_424K);
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2017-08-19 15:49:41 +08:00
|
|
|
if (wait) {
|
|
|
|
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)) {
|
|
|
|
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
|
|
|
}
|
|
|
|
WDT_HIT();
|
|
|
|
}
|
|
|
|
}
|
2017-08-31 19:24:12 +08:00
|
|
|
|
|
|
|
c = 0;
|
2010-02-21 05:24:25 +08:00
|
|
|
for(;;) {
|
2017-08-31 19:24:12 +08:00
|
|
|
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
2010-02-21 05:24:25 +08:00
|
|
|
AT91C_BASE_SSC->SSC_THR = cmd[c];
|
2016-04-10 18:58:04 +08:00
|
|
|
if( ++c >= len) break;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
2017-08-19 15:49:41 +08:00
|
|
|
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2018-01-22 01:34:29 +08:00
|
|
|
WDT_HIT();
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2017-08-19 15:49:41 +08:00
|
|
|
if (samples) {
|
|
|
|
if (wait)
|
|
|
|
*samples = (c + *wait) << 3;
|
|
|
|
else
|
|
|
|
*samples = c << 3;
|
|
|
|
}
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// DEMODULATE tag answer
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) {
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
int max = 0, maxPos = 0, skip = 4;
|
|
|
|
int k = 0; // this will be our return value
|
|
|
|
|
|
|
|
// First, correlate for SOF
|
|
|
|
for (i = 0; i < samplecount; i++) {
|
|
|
|
int corr = 0;
|
|
|
|
for ( j = 0; j < ARRAYLEN(FrameSOF); j += skip) {
|
|
|
|
corr += FrameSOF[j] * dest[i+(j/skip)];
|
|
|
|
}
|
|
|
|
if (corr > max) {
|
|
|
|
max = corr;
|
|
|
|
maxPos = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// DbpString("SOF at %d, correlation %d", maxPos,max/(ARRAYLEN(FrameSOF)/skip));
|
|
|
|
|
|
|
|
// greg - If correlation is less than 1 then there's little point in continuing
|
|
|
|
if ((max / (ARRAYLEN(FrameSOF)/skip) ) < 1)
|
|
|
|
return k;
|
|
|
|
|
|
|
|
i = maxPos + ARRAYLEN(FrameSOF) / skip;
|
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
uint8_t outBuf[ISO15_MAX_FRAME];
|
2017-09-04 19:56:57 +08:00
|
|
|
memset(outBuf, 0, sizeof(outBuf));
|
|
|
|
uint8_t mask = 0x01;
|
|
|
|
for(;;) {
|
|
|
|
int corr0 = 0, corr1 = 0, corrEOF = 0;
|
|
|
|
for (j = 0; j < ARRAYLEN(Logic0); j += skip) {
|
|
|
|
corr0 += Logic0[j] * dest[i+(j/skip)];
|
|
|
|
}
|
|
|
|
for (j = 0; j < ARRAYLEN(Logic1); j += skip) {
|
|
|
|
corr1 += Logic1[j] * dest[i+(j/skip)];
|
|
|
|
}
|
|
|
|
for (j = 0; j < ARRAYLEN(FrameEOF); j += skip) {
|
|
|
|
corrEOF += FrameEOF[j] * dest[i+(j/skip)];
|
|
|
|
}
|
|
|
|
// Even things out by the length of the target waveform.
|
|
|
|
corr0 *= 4;
|
|
|
|
corr1 *= 4;
|
2018-01-29 22:58:00 +08:00
|
|
|
// if (MF_DBGLEVEL >= MF_DBG_EXTENDED)
|
2017-09-04 19:56:57 +08:00
|
|
|
// Dbprintf("Corr1 %d, Corr0 %d, CorrEOF %d", corr1, corr0, corrEOF);
|
|
|
|
|
|
|
|
if (corrEOF > corr1 && corrEOF > corr0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (corr1 > corr0) {
|
|
|
|
i += ARRAYLEN(Logic1) / skip;
|
|
|
|
outBuf[k] |= mask;
|
|
|
|
} else {
|
|
|
|
i += ARRAYLEN(Logic0) / skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask <<= 1;
|
|
|
|
|
|
|
|
if (mask == 0) {
|
|
|
|
k++;
|
|
|
|
mask = 0x01;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( i + (int)ARRAYLEN(FrameEOF)) >= samplecount-1) {
|
2018-01-29 22:58:00 +08:00
|
|
|
//Dbprintf("[!] ran off end! %d | %d",( i + (int)ARRAYLEN(FrameEOF)), samplecount-1);
|
2017-09-04 19:56:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("ice: demod bytes %u", k);
|
2017-09-05 04:48:35 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
if (mask != 0x01) { // this happens, when we miss the EOF
|
|
|
|
|
|
|
|
// TODO: for some reason this happens quite often
|
2018-02-14 22:48:28 +08:00
|
|
|
if (MF_DBGLEVEL >= MF_DBG_ERROR && k != 0) Dbprintf("[!] error, uneven octet! (extra bits!) mask %02x", mask);
|
2017-09-04 19:56:57 +08:00
|
|
|
//if (mask < 0x08) k--; // discard the last uneven octet;
|
|
|
|
// 0x08 is an assumption - but works quite often
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < k; i++)
|
|
|
|
received[i] = outBuf[i];
|
|
|
|
|
|
|
|
// return the number of bytes demodulated
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// Read from Tag
|
|
|
|
// Parameters:
|
2017-09-04 19:56:57 +08:00
|
|
|
// received
|
2010-10-19 22:25:17 +08:00
|
|
|
// samples
|
|
|
|
// elapsed
|
|
|
|
// returns:
|
|
|
|
// number of decoded bytes
|
2017-09-04 19:56:57 +08:00
|
|
|
// logging enabled
|
2017-09-05 04:48:35 +08:00
|
|
|
static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed) {
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
#define SIGNAL_BUFF_SIZE 15000
|
|
|
|
// get current clock
|
|
|
|
uint32_t time_0 = GetCountSspClk();
|
|
|
|
uint32_t time_stop = 0;
|
2017-09-04 19:56:57 +08:00
|
|
|
bool getNext = false;
|
|
|
|
int counter = 0, ci = 0, cq = 0;
|
2017-09-05 04:48:35 +08:00
|
|
|
//volatile uint32_t r;
|
|
|
|
uint8_t *buf = BigBuf_malloc(SIGNAL_BUFF_SIZE);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
if (elapsed) *elapsed = 0;
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
2017-09-27 18:12:43 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
// for (counter = 0; counter < wait;) {
|
|
|
|
|
|
|
|
// WDT_HIT();
|
|
|
|
|
|
|
|
// if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
|
|
|
// AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing!
|
|
|
|
// counter++;
|
|
|
|
// }
|
|
|
|
// if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
|
|
|
// r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// counter = 0;
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
for(;;) {
|
2017-08-21 23:17:43 +08:00
|
|
|
WDT_HIT();
|
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
|
|
|
AT91C_BASE_SSC->SSC_THR = 0x00; //0x43;
|
|
|
|
// To make use of exact timing of next command from reader!!
|
|
|
|
if (elapsed) (*elapsed)++;
|
|
|
|
}
|
2017-09-04 19:56:57 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
|
|
|
|
|
|
|
ci = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
|
|
|
|
|
|
|
// LSB is a FPGA singal bit
|
|
|
|
ci >>= 1;
|
|
|
|
ci = ABS(ci);
|
2010-02-21 05:24:25 +08:00
|
|
|
|
|
|
|
// The samples are correlations against I and Q versions of the
|
|
|
|
// tone that the tag AM-modulates, so every other sample is I,
|
|
|
|
// every other is Q. We just want power, so abs(I) + abs(Q) is
|
|
|
|
// close to what we want.
|
2016-08-05 03:37:43 +08:00
|
|
|
// iceman 2016, amplitude sqrt(abs(i) + abs(q))
|
2017-09-04 19:56:57 +08:00
|
|
|
if (getNext) {
|
|
|
|
|
|
|
|
buf[counter++] = (uint8_t)(MAX(ci,cq) + (MIN(ci, cq) >> 1));
|
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
if (counter >= SIGNAL_BUFF_SIZE)
|
2010-02-21 05:24:25 +08:00
|
|
|
break;
|
|
|
|
} else {
|
2017-09-04 19:56:57 +08:00
|
|
|
cq = ci;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
getNext = !getNext;
|
|
|
|
}
|
2017-09-04 19:56:57 +08:00
|
|
|
}
|
2017-09-05 04:48:35 +08:00
|
|
|
time_stop = GetCountSspClk() - time_0 ;
|
2017-09-04 19:56:57 +08:00
|
|
|
int len = DemodAnswer(received, buf, counter);
|
2017-09-05 04:48:35 +08:00
|
|
|
LogTrace(received, len, time_0 << 4, time_stop << 4, NULL, false);
|
2017-09-04 19:56:57 +08:00
|
|
|
BigBuf_free();
|
|
|
|
return len;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
// Now the GetISO15693 message from sniffing command
|
2017-09-04 19:56:57 +08:00
|
|
|
// logging enable,
|
|
|
|
static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elapsed) {
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
bool getNext = false;
|
|
|
|
int counter = 0, ci = 0, cq = 0;
|
|
|
|
uint32_t time_0 = 0, time_stop = 0;
|
|
|
|
uint8_t *buf = BigBuf_get_addr();
|
|
|
|
|
|
|
|
// get current clock
|
|
|
|
time_0 = GetCountSspClk();
|
|
|
|
|
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
2017-09-27 18:12:43 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
for(;;) {
|
2017-08-21 23:17:43 +08:00
|
|
|
WDT_HIT();
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))
|
2010-02-21 05:24:25 +08:00
|
|
|
AT91C_BASE_SSC->SSC_THR = 0x43;
|
2016-03-13 14:16:42 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
ci = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
|
|
|
|
|
|
|
// LSB is a FPGA singal bit
|
|
|
|
ci >>= 1;
|
|
|
|
ci = ABS(ci);
|
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
// The samples are correlations against I and Q versions of the
|
|
|
|
// tone that the tag AM-modulates, so every other sample is I,
|
|
|
|
// every other is Q. We just want power, so abs(I) + abs(Q) is
|
|
|
|
// close to what we want.
|
2017-09-14 17:09:21 +08:00
|
|
|
if (getNext) {
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
buf[counter++] = (uint8_t)(MAX(ci,cq) + (MIN(ci, cq) >> 1));
|
|
|
|
|
|
|
|
if(counter >= 20000)
|
2010-02-21 05:24:25 +08:00
|
|
|
break;
|
|
|
|
} else {
|
2017-09-04 19:56:57 +08:00
|
|
|
cq = ci;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
getNext = !getNext;
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
time_stop = GetCountSspClk() - time_0;
|
2017-09-04 19:56:57 +08:00
|
|
|
int k = DemodAnswer(received, buf, counter);
|
2017-09-05 04:48:35 +08:00
|
|
|
LogTrace(received, k, time_0 << 4, time_stop << 4, NULL, false);
|
2017-09-04 19:56:57 +08:00
|
|
|
return k;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Start to read an ISO 15693 tag. We send an identify request, then wait
|
|
|
|
// 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.
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-09-04 19:56:57 +08:00
|
|
|
void AcquireRawAdcSamplesIso15693(void) {
|
2017-07-07 18:52:51 +08:00
|
|
|
int c = 0, getNext = false;
|
2016-04-10 18:58:04 +08:00
|
|
|
volatile uint32_t r;
|
2017-09-04 19:56:57 +08:00
|
|
|
int ci = 0, cq = 0;
|
2017-08-31 19:24:12 +08:00
|
|
|
|
|
|
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
2010-02-21 05:24:25 +08:00
|
|
|
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
2017-08-31 19:24:12 +08:00
|
|
|
FpgaSetupSsc();
|
2010-02-21 05:24:25 +08:00
|
|
|
// Give the tags time to energize
|
2017-09-27 18:12:43 +08:00
|
|
|
//FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
// Now send the command
|
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
|
2017-09-27 18:12:43 +08:00
|
|
|
SpinDelay(200);
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint8_t *buf = BigBuf_get_addr();
|
|
|
|
|
|
|
|
uint32_t time_start = GetCountSspClk();
|
2017-09-05 16:10:24 +08:00
|
|
|
uint8_t cmd[CMD_ID_RESP] = {0};
|
|
|
|
BuildIdentifyRequest(cmd);
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
// sending command
|
2010-02-21 05:24:25 +08:00
|
|
|
c = 0;
|
|
|
|
for(;;) {
|
2017-08-31 19:24:12 +08:00
|
|
|
WDT_HIT();
|
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
|
|
|
AT91C_BASE_SSC->SSC_THR = ToSend[c];
|
2017-09-04 19:56:57 +08:00
|
|
|
c++;
|
|
|
|
if(c == ToSendMax + 3) {
|
|
|
|
break;
|
|
|
|
}
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
2017-08-31 19:24:12 +08:00
|
|
|
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
|
2017-09-05 16:10:24 +08:00
|
|
|
LogTrace(cmd, CMD_ID_RESP, time_start << 4, (GetCountSspClk() - time_start) << 4, NULL, true);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
|
|
|
|
|
|
|
c = 0;
|
|
|
|
for(;;) {
|
2017-08-31 19:24:12 +08:00
|
|
|
WDT_HIT();
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))
|
2010-02-21 05:24:25 +08:00
|
|
|
AT91C_BASE_SSC->SSC_THR = 0x43;
|
2016-04-10 18:58:04 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
2016-08-05 03:37:43 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
ci = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
// LSB is a FPGA singal bit
|
|
|
|
ci >>= 1;
|
|
|
|
|
|
|
|
ci = ABS(ci);
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// The samples are correlations against I and Q versions of the
|
|
|
|
// tone that the tag AM-modulates, so every other sample is I,
|
|
|
|
// every other is Q. We just want power, so abs(I) + abs(Q) is
|
|
|
|
// close to what we want.
|
2017-09-04 19:56:57 +08:00
|
|
|
// iceman 2016, amplitude sqrt(abs(i) + abs(q))
|
|
|
|
if (getNext) {
|
2016-04-10 18:58:04 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
buf[c++] = (uint8_t)(MAX(ci,cq) + (MIN(ci, cq) >> 1));
|
|
|
|
|
|
|
|
if (c >= 7000) break;
|
2016-04-10 18:58:04 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
} else {
|
2017-09-04 19:56:57 +08:00
|
|
|
cq = ci;
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
getNext = !getNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
// switch_off, initreader, no logging
|
2017-08-31 19:24:12 +08:00
|
|
|
void RecordRawAdcSamplesIso15693(void) {
|
2015-01-05 22:51:27 +08:00
|
|
|
|
2017-07-07 18:52:51 +08:00
|
|
|
int c = 0, getNext = false;
|
2017-09-04 19:56:57 +08:00
|
|
|
int ci = 0, cq = 0;
|
2017-08-31 19:24:12 +08:00
|
|
|
|
|
|
|
Iso15693InitReader();
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint8_t *buf = BigBuf_get_addr();
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-08-31 19:24:12 +08:00
|
|
|
for(;;) {
|
|
|
|
WDT_HIT();
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
|
|
|
AT91C_BASE_SSC->SSC_THR = 0x43;
|
|
|
|
}
|
|
|
|
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
ci = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
|
|
|
|
|
|
|
// LSB is a FPGA singal bit
|
|
|
|
ci >>= 1;
|
|
|
|
|
|
|
|
ci = ABS(ci);
|
2010-10-19 22:25:17 +08:00
|
|
|
// The samples are correlations against I and Q versions of the
|
|
|
|
// tone that the tag AM-modulates, so every other sample is I,
|
|
|
|
// every other is Q. We just want power, so abs(I) + abs(Q) is
|
|
|
|
// close to what we want.
|
2017-08-31 19:24:12 +08:00
|
|
|
if (getNext) {
|
2017-09-04 19:56:57 +08:00
|
|
|
|
|
|
|
buf[c++] = (uint8_t)(MAX(ci,cq) + (MIN(ci, cq) >> 1));
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2016-08-05 03:37:43 +08:00
|
|
|
if(c >= 7000)
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
} else {
|
2017-09-04 19:56:57 +08:00
|
|
|
cq = ci;
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getNext = !getNext;
|
|
|
|
}
|
|
|
|
}
|
2017-08-31 19:24:12 +08:00
|
|
|
|
|
|
|
Dbprintf("done");
|
|
|
|
switch_off();
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the proxmark as iso15k reader
|
2012-06-21 01:20:21 +08:00
|
|
|
// (this might produces glitches that confuse some tags
|
2017-08-31 19:24:12 +08:00
|
|
|
void Iso15693InitReader(void) {
|
|
|
|
LEDsoff();
|
2017-09-04 19:56:57 +08:00
|
|
|
clear_trace();
|
|
|
|
set_tracing(true);
|
|
|
|
|
2014-06-20 07:02:59 +08:00
|
|
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
2010-10-19 22:25:17 +08:00
|
|
|
|
|
|
|
// Start from off (no field generated)
|
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
2012-06-21 01:20:21 +08:00
|
|
|
SpinDelay(10);
|
2010-10-19 22:25:17 +08:00
|
|
|
|
|
|
|
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
FpgaSetupSsc();
|
|
|
|
|
|
|
|
// Give the tags time to energize
|
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
2017-09-27 18:12:43 +08:00
|
|
|
SpinDelay(200);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
|
|
|
// Start the timer
|
|
|
|
StartCountSspClk();
|
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED ) DbpString("[+] Iso15693InitReader Exit");
|
2010-10-19 22:25:17 +08:00
|
|
|
|
|
|
|
LED_A_ON();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// ISO 15693 Part 3 - Air Interface
|
|
|
|
// This section basicly contains transmission and receiving of bits
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Encode (into the ToSend buffers) an identify request, which is the first
|
|
|
|
// thing that you must send to a tag to get a response.
|
2017-09-05 16:10:24 +08:00
|
|
|
static void BuildIdentifyRequest(uint8_t *out) {
|
2017-09-04 19:56:57 +08:00
|
|
|
|
|
|
|
uint8_t cmd[CMD_ID_RESP] = {0, ISO15_CMD_INVENTORY, 0, 0, 0};
|
|
|
|
// flags
|
|
|
|
cmd[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
|
2010-10-19 22:25:17 +08:00
|
|
|
// no mask
|
|
|
|
cmd[2] = 0x00;
|
2017-09-04 19:56:57 +08:00
|
|
|
// CRC
|
2018-01-17 04:07:58 +08:00
|
|
|
AddCrc(cmd, 3);
|
2017-09-04 19:56:57 +08:00
|
|
|
// coding as high speed (1 out of 4)
|
|
|
|
CodeIso15693AsReader(cmd, CMD_ID_RESP);
|
2017-09-05 16:10:24 +08:00
|
|
|
memcpy(out, cmd, CMD_ID_RESP);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// uid is in transmission order (which is reverse of display order)
|
2017-09-04 19:56:57 +08:00
|
|
|
/*
|
2017-09-05 16:10:24 +08:00
|
|
|
static void BuildReadBlockRequest(uint8_t **out, uint8_t *uid, uint8_t blockNumber ) {
|
2017-09-04 19:56:57 +08:00
|
|
|
uint8_t cmd[CMD_READ_RESP] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
|
2010-10-19 22:25:17 +08:00
|
|
|
// If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
|
|
|
|
// followed by teh block data
|
|
|
|
// one sub-carrier, inventory, 1 slot, fast rate
|
|
|
|
cmd[0] = (1 << 6)| (1 << 5) | (1 << 1); // no SELECT bit, ADDR bit, OPTION bit
|
|
|
|
// READ BLOCK command code
|
|
|
|
cmd[1] = 0x20;
|
|
|
|
// UID may be optionally specified here
|
|
|
|
// 64-bit UID
|
|
|
|
cmd[2] = uid[0];
|
|
|
|
cmd[3] = uid[1];
|
|
|
|
cmd[4] = uid[2];
|
|
|
|
cmd[5] = uid[3];
|
|
|
|
cmd[6] = uid[4];
|
|
|
|
cmd[7] = uid[5];
|
|
|
|
cmd[8] = uid[6];
|
|
|
|
cmd[9] = uid[7]; // 0xe0; // always e0 (not exactly unique)
|
|
|
|
// Block number to read
|
|
|
|
cmd[10] = blockNumber;//0x00;
|
2017-09-04 19:56:57 +08:00
|
|
|
// CRC
|
2018-01-17 04:07:58 +08:00
|
|
|
AddCrc(cmd, 11);
|
2017-09-04 19:56:57 +08:00
|
|
|
CodeIso15693AsReader(cmd, CMD_READ_RESP);
|
2017-09-05 16:10:24 +08:00
|
|
|
memcpy(out, cmd, CMD_ID_RESP);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
2017-09-04 19:56:57 +08:00
|
|
|
*/
|
2010-10-19 22:25:17 +08:00
|
|
|
|
|
|
|
// Now the VICC>VCD responses when we are simulating a tag
|
2017-09-05 16:10:24 +08:00
|
|
|
static void BuildInventoryResponse(uint8_t *out, uint8_t *uid) {
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint8_t cmd[CMD_INV_RESP] = {0,0,0,0,0,0,0,0,0,0,0,0};
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// one sub-carrier, inventory, 1 slot, fast rate
|
|
|
|
// AFI is at bit 5 (1<<4) when doing an INVENTORY
|
2015-01-05 22:51:27 +08:00
|
|
|
//(1 << 2) | (1 << 5) | (1 << 1);
|
|
|
|
cmd[0] = 0; //
|
|
|
|
cmd[1] = 0; // DSFID (data storage format identifier). 0x00 = not supported
|
2010-10-19 22:25:17 +08:00
|
|
|
// 64-bit UID
|
2015-01-05 22:51:27 +08:00
|
|
|
cmd[2] = uid[7]; //0x32;
|
|
|
|
cmd[3] = uid[6]; //0x4b;
|
|
|
|
cmd[4] = uid[5]; //0x03;
|
|
|
|
cmd[5] = uid[4]; //0x01;
|
|
|
|
cmd[6] = uid[3]; //0x00;
|
|
|
|
cmd[7] = uid[2]; //0x10;
|
|
|
|
cmd[8] = uid[1]; //0x05;
|
|
|
|
cmd[9] = uid[0]; //0xe0;
|
2017-09-04 19:56:57 +08:00
|
|
|
// CRC
|
2018-01-17 04:07:58 +08:00
|
|
|
AddCrc(cmd, 10);
|
2017-09-04 19:56:57 +08:00
|
|
|
CodeIso15693AsReader(cmd, CMD_INV_RESP);
|
2017-09-05 16:10:24 +08:00
|
|
|
memcpy(out, cmd, CMD_ID_RESP);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
2012-06-21 01:20:21 +08:00
|
|
|
// Universal Method for sending to and recv bytes from a tag
|
2010-10-19 22:25:17 +08:00
|
|
|
// init ... should we initialize the reader?
|
|
|
|
// speed ... 0 low speed, 1 hi speed
|
|
|
|
// **recv will return you a pointer to the received data
|
|
|
|
// If you do not need the answer use NULL for *recv[]
|
|
|
|
// return: lenght of received data
|
2017-09-04 19:56:57 +08:00
|
|
|
// logging enabled
|
|
|
|
int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outdata) {
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
int t_samples = 0, wait = 0, elapsed = 0, answer_len = 0;
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2017-08-31 19:24:12 +08:00
|
|
|
LEDsoff();
|
2016-08-05 03:37:43 +08:00
|
|
|
|
2015-06-30 04:36:55 +08:00
|
|
|
if (init) Iso15693InitReader();
|
2017-09-04 19:56:57 +08:00
|
|
|
|
|
|
|
LED_A_ON();
|
2015-06-30 04:36:55 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
if (!speed)
|
|
|
|
CodeIso15693AsReader256(send, sendlen); // low speed (1 out of 256)
|
|
|
|
else
|
|
|
|
CodeIso15693AsReader(send, sendlen); // high speed (1 out of 4)
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-08-31 19:24:12 +08:00
|
|
|
LED_A_INV();
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint32_t time_start = GetCountSspClk();
|
|
|
|
|
|
|
|
TransmitTo15693Tag(ToSend, ToSendMax, &t_samples, &wait);
|
2017-09-05 04:48:35 +08:00
|
|
|
LogTrace(send, sendlen, time_start << 4, (GetCountSspClk() - time_start) << 4, NULL, true);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// Now wait for a response
|
2017-09-04 19:56:57 +08:00
|
|
|
if (outdata != NULL) {
|
|
|
|
LED_B_INV();
|
2017-09-05 04:48:35 +08:00
|
|
|
answer_len = GetIso15693AnswerFromTag(outdata, &elapsed);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
2016-01-21 00:13:25 +08:00
|
|
|
LEDsoff();
|
2017-09-04 19:56:57 +08:00
|
|
|
return answer_len;
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
// Debug Functions
|
|
|
|
// --------------------------------------------------------------------
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
// Decodes a message from a tag and displays its metadata and content
|
|
|
|
#define DBD15STATLEN 48
|
|
|
|
void DbdecodeIso15693Answer(int len, uint8_t *d) {
|
2016-08-05 03:37:43 +08:00
|
|
|
char status[DBD15STATLEN+1] = {0};
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2016-08-05 03:37:43 +08:00
|
|
|
if (len > 3) {
|
|
|
|
if (d[0] & ( 1 << 3 ))
|
|
|
|
strncat(status, "ProtExt ", DBD15STATLEN);
|
|
|
|
if (d[0] & 1) {
|
2010-10-19 22:25:17 +08:00
|
|
|
// error
|
2016-08-05 03:37:43 +08:00
|
|
|
strncat(status, "Error ", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
switch (d[1]) {
|
|
|
|
case 0x01:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "01: not supported", DBD15STATLEN);
|
2010-02-21 05:24:25 +08:00
|
|
|
break;
|
2010-10-19 22:25:17 +08:00
|
|
|
case 0x02:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "02: not recognized", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x03:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "03: opt not supported", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x0f:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "0F: no info", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x10:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "10: dont exist", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x11:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "11: lock again", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x12:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "12: locked", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x13:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "13: program error", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
case 0x14:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "14: lock error", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "unknown error", DBD15STATLEN);
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2016-08-05 03:37:43 +08:00
|
|
|
strncat(status ," " ,DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
} else {
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status ,"No error ", DBD15STATLEN);
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2018-02-01 22:19:47 +08:00
|
|
|
if (CheckCrc(d, len))
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "[+] crc OK", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
else
|
2018-01-17 04:07:58 +08:00
|
|
|
strncat(status, "[!] crc fail", DBD15STATLEN);
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if ( MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("%s", status);
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Functions called via USB/Client
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-09-04 19:56:57 +08:00
|
|
|
// Act as ISO15693 reader, perform anti-collision and then attempt to read a sector
|
2010-02-21 05:24:25 +08:00
|
|
|
// all demodulation performed in arm rather than host. - greg
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-09-04 19:56:57 +08:00
|
|
|
// ok
|
|
|
|
// parameter is unused !?!
|
2017-08-31 19:24:12 +08:00
|
|
|
void ReaderIso15693(uint32_t parameter) {
|
2010-02-21 05:24:25 +08:00
|
|
|
int answerLen1 = 0;
|
2017-09-04 19:56:57 +08:00
|
|
|
//int answerLen2 = 0;
|
|
|
|
//int answerLen3 = 0;
|
2017-09-05 04:48:35 +08:00
|
|
|
int tsamples = 0, wait = 0, elapsed = 0;
|
2017-08-31 19:24:12 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint8_t uid[8] = {0,0,0,0,0,0,0,0};
|
2015-01-05 22:51:27 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
// set up device/fpga
|
|
|
|
Iso15693InitReader();
|
|
|
|
|
|
|
|
uint8_t *answer1 = BigBuf_malloc(50);
|
|
|
|
uint8_t *answer2 = BigBuf_malloc(50);
|
|
|
|
//uint8_t *answer3 = BigBuf_malloc(50);
|
2010-02-21 05:24:25 +08:00
|
|
|
// Blank arrays
|
2017-09-04 19:56:57 +08:00
|
|
|
memset(answer1, 0x00, 50);
|
|
|
|
memset(answer2, 0x00, 50);
|
|
|
|
//memset(answer3, 0x00, 50);
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-08-31 19:24:12 +08:00
|
|
|
// Now send the IDENTIFY command
|
2010-02-21 05:24:25 +08:00
|
|
|
// FIRST WE RUN AN INVENTORY TO GET THE TAG UID
|
|
|
|
// THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME
|
2017-09-04 19:56:57 +08:00
|
|
|
uint32_t time_start = GetCountSspClk();
|
2017-09-05 16:10:24 +08:00
|
|
|
uint8_t cmd[CMD_ID_RESP] = {0};
|
|
|
|
BuildIdentifyRequest( cmd );
|
2017-09-04 19:56:57 +08:00
|
|
|
TransmitTo15693Tag(ToSend, ToSendMax, &tsamples, &wait);
|
2017-09-05 16:10:24 +08:00
|
|
|
LogTrace(cmd, CMD_ID_RESP, time_start << 4, (GetCountSspClk() - time_start) << 4, NULL, true);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
// Now wait for a response
|
2017-09-05 04:48:35 +08:00
|
|
|
answerLen1 = GetIso15693AnswerFromTag(answer1, &elapsed) ;
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-08-31 19:24:12 +08:00
|
|
|
// we should do a better check than this
|
|
|
|
if (answerLen1 >= 12) {
|
2017-09-04 19:56:57 +08:00
|
|
|
uid[0] = answer1[9]; // always E0
|
|
|
|
uid[1] = answer1[8]; // IC Manufacturer code
|
|
|
|
uid[2] = answer1[7];
|
|
|
|
uid[3] = answer1[6];
|
|
|
|
uid[4] = answer1[5];
|
|
|
|
uid[5] = answer1[4];
|
|
|
|
uid[6] = answer1[3];
|
|
|
|
uid[7] = answer1[2];
|
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if ( MF_DBGLEVEL >= MF_DBG_EXTENDED) {
|
|
|
|
Dbprintf("[+] UID = %02X%02X%02X%02X%02X%02X%02X%02X",
|
2017-09-04 19:56:57 +08:00
|
|
|
uid[0], uid[1], uid[2], uid[3],
|
|
|
|
uid[4], uid[5], uid[5], uid[6]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// send UID back to client.
|
|
|
|
// arg0 = 1 = OK
|
|
|
|
// arg1 = len of response (12 bytes)
|
|
|
|
// arg2 = rtf
|
|
|
|
// asbytes = uid.
|
|
|
|
cmd_send(CMD_ACK, 1, sizeof(uid), 0, uid, sizeof(uid));
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if ( MF_DBGLEVEL >= MF_DBG_EXTENDED) {
|
|
|
|
Dbprintf("[+] %d octets read from IDENTIFY request:", answerLen1);
|
2017-09-04 19:56:57 +08:00
|
|
|
DbdecodeIso15693Answer(answerLen1, answer1);
|
|
|
|
Dbhexdump(answerLen1, answer1, true);
|
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
// DEBUG read all pages
|
|
|
|
/*
|
2018-01-29 22:58:00 +08:00
|
|
|
if (answerLen1 >= 12 && MF_DBGLEVEL >= MF_DBG_EXTENDED) {
|
2016-08-05 03:37:43 +08:00
|
|
|
i = 0;
|
|
|
|
while ( i < 32 ) { // sanity check, assume max 32 pages
|
2017-09-04 19:56:57 +08:00
|
|
|
|
|
|
|
cmdlen = BuildReadBlockRequest(cmd, uid, i);
|
|
|
|
|
|
|
|
TransmitTo15693Tag(ToSend, ToSendMax, &tsamples, &wait);
|
2017-09-05 04:48:35 +08:00
|
|
|
LogTrace(cmd, cmdlen, time_start<<4, (GetCountSspClk()-time_start)<<4, NULL, true);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
answerLen2 = GetIso15693AnswerFromTag(answer2, &elapsed);
|
2017-09-04 19:56:57 +08:00
|
|
|
if (answerLen2 > 0) {
|
2016-08-05 03:37:43 +08:00
|
|
|
Dbprintf("READ SINGLE BLOCK %d returned %d octets:", i, answerLen2);
|
|
|
|
DbdecodeIso15693Answer(answerLen2, answer2);
|
|
|
|
Dbhexdump(answerLen2, answer2, true);
|
2010-10-19 22:25:17 +08:00
|
|
|
if ( *((uint32_t*) answer2) == 0x07160101 ) break; // exit on NoPageErr
|
|
|
|
}
|
2017-07-07 18:52:51 +08:00
|
|
|
i++;
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-04 19:56:57 +08:00
|
|
|
*/
|
2017-08-31 19:24:12 +08:00
|
|
|
switch_off();
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands
|
|
|
|
// all demodulation performed in arm rather than host. - greg
|
2017-08-31 19:24:12 +08:00
|
|
|
void SimTagIso15693(uint32_t parameter, uint8_t *uid) {
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
2017-08-31 19:24:12 +08:00
|
|
|
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
|
|
|
FpgaSetupSsc();
|
|
|
|
// Start from off (no field generated)
|
|
|
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
|
|
|
SpinDelay(200);
|
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
LED_A_ON();
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint32_t time_start = 0;
|
|
|
|
int ans = 0, samples = 0, tsamples = 0;
|
|
|
|
int wait = 0, elapsed = 0;
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
Dbprintf("ISO-15963 Simulating uid: %02X%02X%02X%02X%02X%02X%02X%02X", uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7]);
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-09-05 04:48:35 +08:00
|
|
|
uint8_t buf[ISO15_MAX_FRAME];
|
|
|
|
memset(buf, 0x00, sizeof(buf));
|
2015-01-05 22:51:27 +08:00
|
|
|
|
2010-02-21 05:24:25 +08:00
|
|
|
LED_C_ON();
|
|
|
|
|
2017-08-01 00:24:53 +08:00
|
|
|
// Build a suitable reponse to the reader INVENTORY cocmmand
|
|
|
|
// not so obsvious, but in the call to BuildInventoryResponse, the command is copied to the global ToSend buffer used below.
|
2017-09-05 16:10:24 +08:00
|
|
|
uint8_t cmd[CMD_INV_RESP] = {0};
|
|
|
|
BuildInventoryResponse(cmd, uid);
|
2017-08-01 00:24:53 +08:00
|
|
|
|
2017-08-31 19:24:12 +08:00
|
|
|
while (!BUTTON_PRESS() && !usb_poll_validate_length() ) {
|
2017-07-31 23:55:21 +08:00
|
|
|
WDT_HIT();
|
2015-01-05 22:51:27 +08:00
|
|
|
|
2017-07-31 23:55:21 +08:00
|
|
|
// Listen to reader
|
2017-09-04 19:56:57 +08:00
|
|
|
ans = GetIso15693AnswerFromSniff(buf, &samples, &elapsed) ;
|
2010-02-21 05:24:25 +08:00
|
|
|
|
2017-08-01 00:24:53 +08:00
|
|
|
// we should do a better check than this
|
2017-08-31 19:24:12 +08:00
|
|
|
if (ans >= 1 ) {
|
2017-09-04 19:56:57 +08:00
|
|
|
|
|
|
|
time_start = GetCountSspClk();
|
2017-08-01 00:24:53 +08:00
|
|
|
TransmitTo15693Reader(ToSend, ToSendMax, &tsamples, &wait);
|
2017-09-05 16:10:24 +08:00
|
|
|
LogTrace(cmd, CMD_INV_RESP, time_start << 4, (GetCountSspClk() - time_start) << 4, NULL, true);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {
|
|
|
|
Dbprintf("[+] %d octets read from reader command: %x %x %x %x %x %x %x %x", ans,
|
2017-09-14 17:09:21 +08:00
|
|
|
buf[0], buf[1], buf[2], buf[3],
|
|
|
|
buf[4], buf[5], buf[6], buf[7]
|
|
|
|
);
|
|
|
|
}
|
2017-08-01 00:24:53 +08:00
|
|
|
}
|
2017-07-31 23:55:21 +08:00
|
|
|
}
|
2017-08-31 19:24:12 +08:00
|
|
|
switch_off();
|
2010-02-21 05:24:25 +08:00
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
|
|
|
|
// 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)
|
2017-07-31 23:55:21 +08:00
|
|
|
void BruteforceIso15693Afi(uint32_t speed) {
|
2016-08-05 03:37:43 +08:00
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
uint8_t data[7] = {0,0,0,0,0,0,0};
|
2017-09-05 16:10:24 +08:00
|
|
|
uint8_t buf[ISO15_MAX_FRAME];
|
|
|
|
memset(buf, 0x00, sizeof(buf));
|
2017-09-04 19:56:57 +08:00
|
|
|
int datalen = 0, recvlen = 0;
|
2016-08-05 03:37:43 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
Iso15693InitReader();
|
|
|
|
|
|
|
|
// first without AFI
|
|
|
|
// Tags should respond wihtout AFI and with AFI=0 even when AFI is active
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
data[0] = ISO15_REQ_SUBCARRIER_SINGLE | ISO15_REQ_DATARATE_HIGH | ISO15_REQ_INVENTORY | ISO15_REQINV_SLOT1;
|
2016-08-05 03:37:43 +08:00
|
|
|
data[1] = ISO15_CMD_INVENTORY;
|
|
|
|
data[2] = 0; // mask length
|
2018-02-01 22:19:47 +08:00
|
|
|
AddCrc(data, 3);
|
|
|
|
datalen += 2;
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2017-09-05 16:10:24 +08:00
|
|
|
recvlen = SendDataTag(data, datalen, false, speed, buf);
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
WDT_HIT();
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2016-08-05 03:37:43 +08:00
|
|
|
if (recvlen >= 12) {
|
2017-09-05 16:10:24 +08:00
|
|
|
Dbprintf("NoAFI UID = %s", sprintUID(NULL, buf + 2) );
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// now with AFI
|
2017-09-04 19:56:57 +08:00
|
|
|
data[0] |= ISO15_REQINV_AFI;
|
|
|
|
//data[1] = ISO15_CMD_INVENTORY;
|
2016-08-05 03:37:43 +08:00
|
|
|
data[2] = 0; // AFI
|
|
|
|
data[3] = 0; // mask length
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2018-01-29 20:42:02 +08:00
|
|
|
for (uint16_t i = 0; i < 256; i++) {
|
2017-09-04 19:56:57 +08:00
|
|
|
data[2] = i & 0xFF;
|
2018-02-01 22:19:47 +08:00
|
|
|
AddCrc(data, 4);
|
|
|
|
datalen += 2;
|
2017-09-05 16:10:24 +08:00
|
|
|
recvlen = SendDataTag(data, datalen, false, speed, buf);
|
2010-10-19 22:25:17 +08:00
|
|
|
WDT_HIT();
|
2016-08-05 03:37:43 +08:00
|
|
|
if (recvlen >= 12) {
|
2017-09-05 16:10:24 +08:00
|
|
|
Dbprintf("AFI = %i UID = %s", i, sprintUID(NULL, buf + 2) );
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
2017-09-05 16:31:27 +08:00
|
|
|
|
2017-09-05 16:36:25 +08:00
|
|
|
if (BUTTON_PRESS()) {
|
2017-09-05 16:31:27 +08:00
|
|
|
DbpString("button pressed, aborting..");
|
|
|
|
break;
|
|
|
|
}
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2017-09-05 16:31:27 +08:00
|
|
|
DbpString("AFI Bruteforcing done.");
|
2017-09-05 16:16:37 +08:00
|
|
|
switch_off();
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allows to directly send commands to the tag via the client
|
2017-09-04 19:56:57 +08:00
|
|
|
// Has to increase dialog between device and client.
|
|
|
|
void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data) {
|
|
|
|
|
|
|
|
bool init = true;
|
|
|
|
int buflen = 0;
|
2017-09-05 04:48:35 +08:00
|
|
|
uint8_t buf[ISO15_MAX_FRAME];
|
|
|
|
memset(buf, 0x00, sizeof(buf));
|
2010-10-19 22:25:17 +08:00
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {
|
|
|
|
DbpString("[+] SEND");
|
2017-09-04 19:56:57 +08:00
|
|
|
Dbhexdump(datalen, data, true);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
|
|
|
|
2017-09-04 19:56:57 +08:00
|
|
|
buflen = SendDataTag(data, datalen, init, speed, (recv ? buf : NULL));
|
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
if (recv) {
|
2017-09-05 04:48:35 +08:00
|
|
|
buflen = (buflen > ISO15_MAX_FRAME) ? ISO15_MAX_FRAME : buflen;
|
2017-09-04 19:56:57 +08:00
|
|
|
|
2010-10-19 22:25:17 +08:00
|
|
|
LED_B_ON();
|
2017-09-04 19:56:57 +08:00
|
|
|
cmd_send(CMD_ACK, buflen, 0, 0, buf, buflen);
|
2010-10-19 22:25:17 +08:00
|
|
|
LED_B_OFF();
|
|
|
|
|
2018-01-29 22:58:00 +08:00
|
|
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) {
|
|
|
|
DbpString("[+] RECV");
|
2017-09-04 19:56:57 +08:00
|
|
|
DbdecodeIso15693Answer(buflen, buf);
|
|
|
|
Dbhexdump(buflen, buf, true);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
2017-09-04 19:56:57 +08:00
|
|
|
} else {
|
|
|
|
cmd_send(CMD_ACK,1,0,0,0,0);
|
2010-10-19 22:25:17 +08:00
|
|
|
}
|
2016-08-05 03:37:43 +08:00
|
|
|
}
|