mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
chg: minor clean up in iso15693 commands.
This commit is contained in:
parent
4d354f75fe
commit
eec5780b62
2 changed files with 90 additions and 131 deletions
|
@ -197,6 +197,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid); // simulate an ISO15693 t
|
|||
void BruteforceIso15693Afi(uint32_t speed); // find an AFI of a tag - atrox
|
||||
void DirectTag15693Command(uint32_t datalen,uint32_t speed, uint32_t recv, uint8_t data[]); // send arbitrary commands from CLI - atrox
|
||||
void SetDebugIso15693(uint32_t flag);
|
||||
void Iso15693InitReader(void);
|
||||
|
||||
// iclass.h
|
||||
void RAMFUNC SniffIClass(void);
|
||||
|
|
|
@ -90,8 +90,7 @@ int DEBUG = 0;
|
|||
// resulting data rate is 26,48 kbit/s (fc/512)
|
||||
// cmd ... data
|
||||
// n ... length of data
|
||||
static void CodeIso15693AsReader(uint8_t *cmd, int n)
|
||||
{
|
||||
static void CodeIso15693AsReader(uint8_t *cmd, int n) {
|
||||
int i, j;
|
||||
|
||||
ToSendReset();
|
||||
|
@ -170,8 +169,7 @@ static void CodeIso15693AsReader(uint8_t *cmd, int n)
|
|||
// 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
|
||||
static void CodeIso15693AsReader256(uint8_t *cmd, int n)
|
||||
{
|
||||
static void CodeIso15693AsReader256(uint8_t *cmd, int n) {
|
||||
int i, j;
|
||||
|
||||
ToSendReset();
|
||||
|
@ -212,10 +210,8 @@ static void CodeIso15693AsReader256(uint8_t *cmd, int n)
|
|||
ToSendStuffBit(1);
|
||||
}
|
||||
|
||||
|
||||
// Transmit the command (to the tag) that was placed in ToSend[].
|
||||
static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait)
|
||||
{
|
||||
static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait) {
|
||||
int c;
|
||||
volatile uint32_t r;
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
|
||||
|
@ -236,6 +232,8 @@ static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *w
|
|||
|
||||
c = 0;
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = cmd[c];
|
||||
if( ++c >= len) break;
|
||||
|
@ -243,8 +241,8 @@ static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *w
|
|||
if (AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
||||
}
|
||||
WDT_HIT();
|
||||
}
|
||||
|
||||
if (samples) {
|
||||
if (wait)
|
||||
*samples = (c + *wait) << 3;
|
||||
|
@ -256,11 +254,11 @@ static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *w
|
|||
//-----------------------------------------------------------------------------
|
||||
// Transmit the command (to the reader) that was placed in ToSend[].
|
||||
//-----------------------------------------------------------------------------
|
||||
static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait)
|
||||
{
|
||||
static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait) {
|
||||
int c = 0;
|
||||
volatile uint32_t r;
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR|FPGA_HF_SIMULATOR_MODULATE_424K);
|
||||
|
||||
if (wait) {
|
||||
if (*wait < 10) { *wait = 10; }
|
||||
for (c = 0; c < *wait;) {
|
||||
|
@ -275,7 +273,9 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
|
|||
}
|
||||
}
|
||||
|
||||
c = 0;
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = cmd[c];
|
||||
if( ++c >= len) break;
|
||||
|
@ -283,7 +283,6 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
|
|||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
||||
}
|
||||
WDT_HIT();
|
||||
}
|
||||
if (samples) {
|
||||
if (wait)
|
||||
|
@ -293,7 +292,6 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Read from Tag
|
||||
// Parameters:
|
||||
// receivedResponse
|
||||
|
@ -302,16 +300,15 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
|
|||
// elapsed
|
||||
// returns:
|
||||
// number of decoded bytes
|
||||
static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
|
||||
{
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
|
||||
int c = 0, getNext = false;
|
||||
int8_t prev = 0;
|
||||
static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) {
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
//SpinDelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads
|
||||
|
||||
int c = 0, getNext = false;
|
||||
int8_t prev = 0;
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
|
@ -431,13 +428,12 @@ static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *
|
|||
|
||||
// Now the GetISO15693 message from sniffing command
|
||||
static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) {
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
//SpinDelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads
|
||||
|
||||
int c = 0, getNext = false;
|
||||
int8_t prev = 0;
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
//SpinDelay(60); // greg - experiment to get rid of some of the 0 byte/failed reads
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
@ -559,48 +555,52 @@ static void BuildIdentifyRequest(void);
|
|||
//-----------------------------------------------------------------------------
|
||||
void AcquireRawAdcSamplesIso15693(void)
|
||||
{
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
int c = 0, getNext = false;
|
||||
int8_t prev = 0;
|
||||
volatile uint32_t r;
|
||||
volatile int8_t b;
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
BuildIdentifyRequest();
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
|
||||
FpgaSetupSsc();
|
||||
|
||||
// Give the tags time to energize
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
SpinDelay(100);
|
||||
|
||||
// Now send the command
|
||||
FpgaSetupSsc();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
|
||||
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
BuildIdentifyRequest();
|
||||
|
||||
c = 0;
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = ToSend[c];
|
||||
if( ++c == ToSendMax+3) break;
|
||||
}
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
r = AT91C_BASE_SSC->SSC_RHR;
|
||||
(void)r;
|
||||
r = AT91C_BASE_SSC->SSC_RHR; (void)r;
|
||||
}
|
||||
WDT_HIT();
|
||||
}
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
|
||||
c = 0;
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY))
|
||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
||||
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
|
||||
int8_t b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
// The samples are correlations against I and Q versions of the
|
||||
// tone that the tag AM-modulates, so every other sample is I,
|
||||
|
@ -620,33 +620,24 @@ void AcquireRawAdcSamplesIso15693(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void RecordRawAdcSamplesIso15693(void)
|
||||
{
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
// switch_off, initreader
|
||||
void RecordRawAdcSamplesIso15693(void) {
|
||||
|
||||
int c = 0, getNext = false;
|
||||
int8_t prev = 0;
|
||||
volatile int8_t b;
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
// Setup SSC
|
||||
FpgaSetupSsc();
|
||||
Iso15693InitReader();
|
||||
|
||||
// Start from off (no field generated)
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
SpinDelay(200);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
SpinDelay(100);
|
||||
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
|
||||
for(;;) {
|
||||
WDT_HIT();
|
||||
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
|
||||
AT91C_BASE_SSC->SSC_THR = 0x43;
|
||||
}
|
||||
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
|
||||
int8_t b;
|
||||
b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
|
||||
|
||||
// The samples are correlations against I and Q versions of the
|
||||
|
@ -663,40 +654,34 @@ void RecordRawAdcSamplesIso15693(void)
|
|||
}
|
||||
|
||||
getNext = !getNext;
|
||||
WDT_HIT();
|
||||
}
|
||||
}
|
||||
Dbprintf("fin record");
|
||||
|
||||
Dbprintf("done");
|
||||
switch_off();
|
||||
}
|
||||
|
||||
|
||||
// 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();
|
||||
void Iso15693InitReader(void) {
|
||||
LEDsoff();
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
// Setup SSC
|
||||
// FpgaSetupSsc();
|
||||
|
||||
// Start from off (no field generated)
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
SpinDelay(10);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
|
||||
FpgaSetupSsc();
|
||||
|
||||
// Give the tags time to energize
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
SpinDelay(250);
|
||||
SpinDelay(60);
|
||||
|
||||
LED_A_ON();
|
||||
LED_B_OFF();
|
||||
LED_C_OFF();
|
||||
LED_D_OFF();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
@ -795,10 +780,9 @@ int SendDataTag(uint8_t *send, int sendlen, int init, int speed, uint8_t **recv)
|
|||
int wait = 0, elapsed = 0;
|
||||
int answerLen = 0;
|
||||
|
||||
LEDsoff();
|
||||
LED_A_ON(); LED_B_ON();
|
||||
|
||||
LED_C_OFF(); LED_D_OFF();
|
||||
|
||||
if (init) Iso15693InitReader();
|
||||
|
||||
// answer is 100bytes long?
|
||||
|
@ -813,14 +797,12 @@ int SendDataTag(uint8_t *send, int sendlen, int init, int speed, uint8_t **recv)
|
|||
CodeIso15693AsReader(send, sendlen);
|
||||
}
|
||||
|
||||
LED_A_ON();
|
||||
LED_B_OFF();
|
||||
LED_A_INV();
|
||||
|
||||
TransmitTo15693Tag(ToSend, ToSendMax, &tsamples, &wait);
|
||||
// Now wait for a response
|
||||
if (recv != NULL) {
|
||||
LED_A_OFF();
|
||||
LED_B_ON();
|
||||
LED_B_INV();
|
||||
answerLen = GetIso15693AnswerFromTag(answer, 100, &samples, &elapsed) ;
|
||||
*recv = answer;
|
||||
}
|
||||
|
@ -906,13 +888,7 @@ void SetDebugIso15693(uint32_t debug) {
|
|||
// Simulate an ISO15693 reader, perform anti-collision and then attempt to read a sector
|
||||
// all demodulation performed in arm rather than host. - greg
|
||||
//-----------------------------------------------------------------------------
|
||||
void ReaderIso15693(uint32_t parameter)
|
||||
{
|
||||
LED_A_ON();
|
||||
LED_B_ON();
|
||||
LED_C_OFF();
|
||||
LED_D_OFF();
|
||||
|
||||
void ReaderIso15693(uint32_t parameter) {
|
||||
int answerLen1 = 0;
|
||||
int answerLen2 = 0;
|
||||
int answerLen3 = 0;
|
||||
|
@ -921,9 +897,8 @@ void ReaderIso15693(uint32_t parameter)
|
|||
int tsamples = 0;
|
||||
int wait = 0;
|
||||
int elapsed = 0;
|
||||
uint8_t TagUID[8] = {0x00};
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
uint8_t TagUID[8] = {0x00};
|
||||
|
||||
uint8_t *answer1 = BigBuf_malloc(100);
|
||||
uint8_t *answer2 = BigBuf_malloc(100);
|
||||
|
@ -933,36 +908,21 @@ void ReaderIso15693(uint32_t parameter)
|
|||
memset(answer2, 0x00, 100);
|
||||
memset(answer3, 0x00, 100);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
// Setup SSC
|
||||
FpgaSetupSsc();
|
||||
|
||||
// Start from off (no field generated)
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
SpinDelay(200);
|
||||
|
||||
// Give the tags time to energize
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
|
||||
SpinDelay(200);
|
||||
|
||||
LED_A_ON();
|
||||
LED_B_OFF();
|
||||
LED_C_OFF();
|
||||
LED_D_OFF();
|
||||
|
||||
// Now send the IDENTIFY command
|
||||
// FIRST WE RUN AN INVENTORY TO GET THE TAG UID
|
||||
// THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME
|
||||
|
||||
// Now send the IDENTIFY command
|
||||
BuildIdentifyRequest();
|
||||
|
||||
// set up device/fpga
|
||||
Iso15693InitReader();
|
||||
|
||||
TransmitTo15693Tag(ToSend,ToSendMax,&tsamples, &wait);
|
||||
|
||||
// Now wait for a response
|
||||
answerLen1 = GetIso15693AnswerFromTag(answer1, 100, &samples, &elapsed) ;
|
||||
|
||||
if (answerLen1 >= 12) // we should do a better check than this
|
||||
{
|
||||
// we should do a better check than this
|
||||
if (answerLen1 >= 12) {
|
||||
TagUID[0] = answer1[2];
|
||||
TagUID[1] = answer1[3];
|
||||
TagUID[2] = answer1[4];
|
||||
|
@ -971,7 +931,6 @@ void ReaderIso15693(uint32_t parameter)
|
|||
TagUID[5] = answer1[7];
|
||||
TagUID[6] = answer1[8]; // IC Manufacturer code
|
||||
TagUID[7] = answer1[9]; // always E0
|
||||
|
||||
}
|
||||
|
||||
Dbprintf("%d octets read from IDENTIFY request:", answerLen1);
|
||||
|
@ -1010,13 +969,22 @@ void ReaderIso15693(uint32_t parameter)
|
|||
}
|
||||
}
|
||||
|
||||
LEDsoff();
|
||||
switch_off();
|
||||
}
|
||||
|
||||
// Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands
|
||||
// all demodulation performed in arm rather than host. - greg
|
||||
void SimTagIso15693(uint32_t parameter, uint8_t *uid)
|
||||
{
|
||||
void SimTagIso15693(uint32_t parameter, uint8_t *uid) {
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
FpgaSetupSsc();
|
||||
|
||||
// Start from off (no field generated)
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
SpinDelay(200);
|
||||
|
||||
LED_A_ON();
|
||||
|
||||
int ans = 0;
|
||||
|
@ -1027,18 +995,9 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid)
|
|||
|
||||
Dbprintf("iso15963 Simulating uid: %x %x %x %x %x %x %x %x", uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7]);
|
||||
|
||||
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
|
||||
|
||||
uint8_t *buf = BigBuf_malloc(100);
|
||||
memset(buf, 0x00, 100);
|
||||
|
||||
SetAdcMuxFor(GPIO_MUXSEL_HIPKD);
|
||||
FpgaSetupSsc();
|
||||
|
||||
// Start from off (no field generated)
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
SpinDelay(200);
|
||||
|
||||
LED_C_ON();
|
||||
|
||||
// Build a suitable reponse to the reader INVENTORY cocmmand
|
||||
|
@ -1060,8 +1019,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid)
|
|||
buf[4], buf[5], buf[6], buf[7], buf[8]);
|
||||
}
|
||||
}
|
||||
LEDsoff();
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
switch_off();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue