1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, split Nov 2006
3 // Modified by Greg Jones, Jan 2009
4 // Modified by Adrian Dabrowski "atrox", Mar-Sept 2010,Oct 2011
5 // Modified by piwi, Oct 2018
7 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
8 // at your option, any later version. See the LICENSE.txt file for the text of
10 //-----------------------------------------------------------------------------
11 // Routines to support ISO 15693. This includes both the reader software and
12 // the `fake tag' modes.
13 //-----------------------------------------------------------------------------
15 // The ISO 15693 describes two transmission modes from reader to tag, and four
16 // transmission modes from tag to reader. As of Oct 2018 this code supports
17 // both reader modes and the high speed variant with one subcarrier from card to reader.
18 // As long as the card fully support ISO 15693 this is no problem, since the
19 // reader chooses both data rates, but some non-standard tags do not.
20 // For card simulation, the code supports both high and low speed modes with one subcarrier.
22 // VCD (reader) -> VICC (tag)
24 // data rate: 1,66 kbit/s (fc/8192)
25 // used for long range
27 // data rate: 26,48 kbit/s (fc/512)
28 // used for short range, high speed
30 // VICC (tag) -> VCD (reader)
32 // ASK / one subcarrier (423,75 khz)
33 // FSK / two subcarriers (423,75 khz && 484,28 khz)
34 // Data Rates / Modes:
35 // low ASK: 6,62 kbit/s
36 // low FSK: 6.67 kbit/s
37 // high ASK: 26,48 kbit/s
38 // high FSK: 26,69 kbit/s
39 //-----------------------------------------------------------------------------
43 // *) UID is always used "transmission order" (LSB), which is reverse to display order
45 // TODO / BUGS / ISSUES:
46 // *) signal decoding is unable to detect collisions.
47 // *) add anti-collision support for inventory-commands
48 // *) read security status of a block
49 // *) sniffing and simulation do not support two subcarrier modes.
50 // *) remove or refactor code under "depricated"
51 // *) document all the functions
54 #include "proxmark3.h"
58 #include "iso15693tools.h"
59 #include "protocols.h"
62 #define arraylen(x) (sizeof(x)/sizeof((x)[0]))
66 ///////////////////////////////////////////////////////////////////////
67 // ISO 15693 Part 2 - Air Interface
68 // This section basicly contains transmission and receiving of bits
69 ///////////////////////////////////////////////////////////////////////
71 #define FrameSOF Iso15693FrameSOF
72 #define Logic0 Iso15693Logic0
73 #define Logic1 Iso15693Logic1
74 #define FrameEOF Iso15693FrameEOF
76 #define Crc(data,datalen) Iso15693Crc(data,datalen)
77 #define AddCrc(data,datalen) Iso15693AddCrc(data,datalen)
78 #define sprintUID(target,uid) Iso15693sprintUID(target,uid)
80 // approximate amplitude=sqrt(ci^2+cq^2) by amplitude = max(|ci|,|cq|) + 1/2*min(|ci|,|cq|)
81 #define AMPLITUDE(ci, cq) (MAX(ABS(ci), ABS(cq)) + MIN(ABS(ci), ABS(cq))/2)
84 #define ISO15693_DMA_BUFFER_SIZE 128
85 #define ISO15693_MAX_RESPONSE_LENGTH 36 // allows read single block with the maximum block size of 256bits. Read multiple blocks not supported yet
86 #define ISO15693_MAX_COMMAND_LENGTH 45 // allows write single block with the maximum block size of 256bits. Write multiple blocks not supported yet
88 // timing. Delays in SSP_CLK ticks.
89 #define DELAY_READER_TO_ARM 8
90 #define DELAY_ARM_TO_READER 1
91 #define DELAY_ISO15693_VCD_TO_VICC 132 // 132/423.75kHz = 311.5us from end of EOF to start of tag response
93 // ---------------------------
95 // ---------------------------
97 // prepare data using "1 out of 4" code for later transmission
98 // resulting data rate is 26.48 kbit/s (fc/512)
100 // n ... length of data
101 static void CodeIso15693AsReader(uint8_t *cmd
, int n
)
107 // Give it a bit of slack at the beginning
108 for(i
= 0; i
< 24; i
++) {
121 for(i
= 0; i
< n
; i
++) {
122 for(j
= 0; j
< 8; j
+= 2) {
123 int these
= (cmd
[i
] >> j
) & 3;
174 // Fill remainder of last byte with 1
175 for(i
= 0; i
< 4; i
++) {
180 // encode data using "1 out of 256" scheme
181 // data rate is 1,66 kbit/s (fc/8192)
182 // is designed for more robust communication over longer distances
183 static void CodeIso15693AsReader256(uint8_t *cmd
, int n
)
189 // Give it a bit of slack at the beginning
190 for(i
= 0; i
< 24; i
++) {
204 for(i
= 0; i
< n
; i
++) {
205 for (j
= 0; j
<=255; j
++) {
221 // Fill remainder of last byte with 1
222 for(i
= 0; i
< 4; i
++) {
230 static void CodeIso15693AsTag(uint8_t *cmd
, int n
)
245 for(int i
= 0; i
< n
; i
++) {
246 for(int j
= 0; j
< 8; j
++) {
247 if ((cmd
[i
] >> j
) & 0x01) {
271 // Transmit the command (to the tag) that was placed in cmd[].
272 static void TransmitTo15693Tag(const uint8_t *cmd
, int len
)
274 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_TX
);
275 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX
);
278 for(int c
= 0; c
< len
; ) {
279 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
)) {
280 AT91C_BASE_SSC
->SSC_THR
= ~cmd
[c
];
288 //-----------------------------------------------------------------------------
289 // Transmit the tag response (to the reader) that was placed in cmd[].
290 //-----------------------------------------------------------------------------
291 static void TransmitTo15693Reader(const uint8_t *cmd
, size_t len
, uint32_t start_time
, bool slow
)
293 // don't use the FPGA_HF_SIMULATOR_MODULATE_424K_8BIT minor mode. It would spoil GetCountSspClk()
294 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR
| FPGA_HF_SIMULATOR_MODULATE_424K
);
296 uint8_t shift_delay
= start_time
& 0x00000007;
297 uint8_t bitmask
= 0x00;
298 for (int i
= 0; i
< shift_delay
; i
++) {
299 bitmask
|= (0x01 << i
);
302 while (GetCountSspClk() < (start_time
& 0xfffffff8)) ;
303 AT91C_BASE_SSC
->SSC_THR
= 0x00; // clear TXRDY
306 uint8_t bits_to_shift
= 0x00;
307 for(size_t c
= 0; c
<= len
; c
++) {
308 uint8_t bits_to_send
= bits_to_shift
<< (8 - shift_delay
) | (c
==len
?0x00:cmd
[c
]) >> shift_delay
;
309 bits_to_shift
= cmd
[c
] & bitmask
;
310 for (int i
= 7; i
>= 0; i
--) {
311 for (int j
= 0; j
< (slow
?4:1); ) {
312 if (AT91C_BASE_SSC
->SSC_SR
& AT91C_SSC_TXRDY
) {
313 if (bits_to_send
>> i
& 0x01) {
314 AT91C_BASE_SSC
->SSC_THR
= 0xff;
316 AT91C_BASE_SSC
->SSC_THR
= 0x00;
328 //=============================================================================
329 // An ISO 15693 decoder for tag responses (one subcarrier only).
330 // Uses cross correlation to identify the SOF, each bit, and EOF.
331 // This function is called 8 times per bit (every 2 subcarrier cycles).
332 // Subcarrier frequency fs is 424kHz, 1/fs = 2,36us,
333 // i.e. function is called every 4,72us
335 // LED C -> ON once we have received the SOF and are expecting the rest.
336 // LED C -> OFF once we have received EOF or are unsynced
338 // Returns: true if we received a EOF
339 // false if we are still waiting for some more
340 //=============================================================================
342 #define SUBCARRIER_DETECT_THRESHOLD 2
343 #define SOF_CORRELATOR_LEN (1<<5)
345 typedef struct DecodeTag
{
348 STATE_TAG_AWAIT_SOF_1
,
349 STATE_TAG_AWAIT_SOF_2
,
350 STATE_TAG_RECEIVING_DATA
,
369 int32_t SOF_corr_prev
;
370 uint8_t SOF_correlator
[SOF_CORRELATOR_LEN
];
373 static int Handle15693SamplesFromTag(int8_t ci
, int8_t cq
, DecodeTag_t
*DecodeTag
)
375 switch(DecodeTag
->state
) {
376 case STATE_TAG_UNSYNCD
:
377 // initialize SOF correlator. We are looking for 12 samples low and 12 samples high.
378 DecodeTag
->SOF_low
= 0;
379 DecodeTag
->SOF_high
= 12;
380 DecodeTag
->SOF_last
= 23;
381 memset(DecodeTag
->SOF_correlator
, 0x00, DecodeTag
->SOF_last
+ 1);
382 DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
] = AMPLITUDE(ci
,cq
);
383 DecodeTag
->SOF_corr
= DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
];
384 DecodeTag
->SOF_corr_prev
= DecodeTag
->SOF_corr
;
385 // initialize Decoder
386 DecodeTag
->posCount
= 0;
387 DecodeTag
->bitCount
= 0;
389 DecodeTag
->state
= STATE_TAG_AWAIT_SOF_1
;
392 case STATE_TAG_AWAIT_SOF_1
:
393 // calculate the correlation in real time. Look at differences only.
394 DecodeTag
->SOF_corr
+= DecodeTag
->SOF_correlator
[DecodeTag
->SOF_low
++];
395 DecodeTag
->SOF_corr
-= 2*DecodeTag
->SOF_correlator
[DecodeTag
->SOF_high
++];
396 DecodeTag
->SOF_last
++;
397 DecodeTag
->SOF_low
&= (SOF_CORRELATOR_LEN
-1);
398 DecodeTag
->SOF_high
&= (SOF_CORRELATOR_LEN
-1);
399 DecodeTag
->SOF_last
&= (SOF_CORRELATOR_LEN
-1);
400 DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
] = AMPLITUDE(ci
,cq
);
401 DecodeTag
->SOF_corr
+= DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
];
403 // if correlation increases for 10 consecutive samples, we are close to maximum correlation
404 if (DecodeTag
->SOF_corr
> DecodeTag
->SOF_corr_prev
+ SUBCARRIER_DETECT_THRESHOLD
) {
405 DecodeTag
->posCount
++;
407 DecodeTag
->posCount
= 0;
410 if (DecodeTag
->posCount
== 10) { // correlation increased 10 times
411 DecodeTag
->state
= STATE_TAG_AWAIT_SOF_2
;
414 DecodeTag
->SOF_corr_prev
= DecodeTag
->SOF_corr
;
418 case STATE_TAG_AWAIT_SOF_2
:
419 // calculate the correlation in real time. Look at differences only.
420 DecodeTag
->SOF_corr
+= DecodeTag
->SOF_correlator
[DecodeTag
->SOF_low
++];
421 DecodeTag
->SOF_corr
-= 2*DecodeTag
->SOF_correlator
[DecodeTag
->SOF_high
++];
422 DecodeTag
->SOF_last
++;
423 DecodeTag
->SOF_low
&= (SOF_CORRELATOR_LEN
-1);
424 DecodeTag
->SOF_high
&= (SOF_CORRELATOR_LEN
-1);
425 DecodeTag
->SOF_last
&= (SOF_CORRELATOR_LEN
-1);
426 DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
] = AMPLITUDE(ci
,cq
);
427 DecodeTag
->SOF_corr
+= DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
];
429 if (DecodeTag
->SOF_corr
>= DecodeTag
->SOF_corr_prev
) { // we are looking for the maximum correlation
430 DecodeTag
->SOF_corr_prev
= DecodeTag
->SOF_corr
;
432 DecodeTag
->lastBit
= SOF_PART1
; // detected 1st part of SOF
433 DecodeTag
->sum1
= DecodeTag
->SOF_correlator
[DecodeTag
->SOF_last
];
435 DecodeTag
->posCount
= 2;
436 DecodeTag
->state
= STATE_TAG_RECEIVING_DATA
;
442 case STATE_TAG_RECEIVING_DATA
:
443 if (DecodeTag
->posCount
== 1) {
448 if (DecodeTag
->posCount
<= 4) {
449 DecodeTag
->sum1
+= AMPLITUDE(ci
, cq
);
451 DecodeTag
->sum2
+= AMPLITUDE(ci
, cq
);
454 if (DecodeTag
->posCount
== 8) {
455 int16_t corr_1
= (DecodeTag
->sum2
- DecodeTag
->sum1
) / 4;
456 int16_t corr_0
= (DecodeTag
->sum1
- DecodeTag
->sum2
) / 4;
457 int16_t corr_EOF
= (DecodeTag
->sum1
+ DecodeTag
->sum2
) / 8;
458 if (corr_EOF
> corr_0
&& corr_EOF
> corr_1
) {
459 DecodeTag
->state
= STATE_TAG_AWAIT_EOF
;
460 } else if (corr_1
> corr_0
) {
462 if (DecodeTag
->lastBit
== SOF_PART1
) { // still part of SOF
463 DecodeTag
->lastBit
= SOF_PART2
;
465 DecodeTag
->lastBit
= LOGIC1
;
466 DecodeTag
->shiftReg
>>= 1;
467 DecodeTag
->shiftReg
|= 0x80;
468 DecodeTag
->bitCount
++;
469 if (DecodeTag
->bitCount
== 8) {
470 DecodeTag
->output
[DecodeTag
->len
] = DecodeTag
->shiftReg
;
472 DecodeTag
->bitCount
= 0;
473 DecodeTag
->shiftReg
= 0;
478 if (DecodeTag
->lastBit
== SOF_PART1
) { // incomplete SOF
479 DecodeTag
->state
= STATE_TAG_UNSYNCD
;
482 DecodeTag
->lastBit
= LOGIC0
;
483 DecodeTag
->shiftReg
>>= 1;
484 DecodeTag
->bitCount
++;
485 if (DecodeTag
->bitCount
== 8) {
486 DecodeTag
->output
[DecodeTag
->len
] = DecodeTag
->shiftReg
;
488 DecodeTag
->bitCount
= 0;
489 DecodeTag
->shiftReg
= 0;
493 DecodeTag
->posCount
= 0;
495 DecodeTag
->posCount
++;
498 case STATE_TAG_AWAIT_EOF
:
499 if (DecodeTag
->lastBit
== LOGIC0
) { // this was already part of EOF
503 DecodeTag
->state
= STATE_TAG_UNSYNCD
;
509 DecodeTag
->state
= STATE_TAG_UNSYNCD
;
518 static void DecodeTagInit(DecodeTag_t
*DecodeTag
, uint8_t *data
)
520 DecodeTag
->output
= data
;
521 DecodeTag
->state
= STATE_TAG_UNSYNCD
;
525 * Receive and decode the tag response, also log to tracebuffer
527 static int GetIso15693AnswerFromTag(uint8_t* response
, int timeout
)
530 int lastRxCounter
, samples
= 0;
532 bool gotFrame
= false;
534 uint16_t dmaBuf
[ISO15693_DMA_BUFFER_SIZE
];
536 // the Decoder data structure
537 DecodeTag_t DecodeTag
;
538 DecodeTagInit(&DecodeTag
, response
);
540 // wait for last transfer to complete
541 while (!(AT91C_BASE_SSC
->SSC_SR
& AT91C_SSC_TXEMPTY
));
543 // And put the FPGA in the appropriate mode
544 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
546 // Setup and start DMA.
547 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
548 FpgaSetupSscDma((uint8_t*) dmaBuf
, ISO15693_DMA_BUFFER_SIZE
);
549 uint16_t *upTo
= dmaBuf
;
550 lastRxCounter
= ISO15693_DMA_BUFFER_SIZE
;
553 int behindBy
= (lastRxCounter
- AT91C_BASE_PDC_SSC
->PDC_RCR
) & (ISO15693_DMA_BUFFER_SIZE
-1);
554 if(behindBy
> maxBehindBy
) {
555 maxBehindBy
= behindBy
;
558 if (behindBy
< 1) continue;
560 ci
= (int8_t)(*upTo
>> 8);
561 cq
= (int8_t)(*upTo
& 0xff);
565 if(upTo
>= dmaBuf
+ ISO15693_DMA_BUFFER_SIZE
) { // we have read all of the DMA buffer content.
566 upTo
= dmaBuf
; // start reading the circular buffer from the beginning
567 lastRxCounter
+= ISO15693_DMA_BUFFER_SIZE
;
569 if (AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_ENDRX
)) { // DMA Counter Register had reached 0, already rotated.
570 AT91C_BASE_PDC_SSC
->PDC_RNPR
= (uint32_t) dmaBuf
; // refresh the DMA Next Buffer and
571 AT91C_BASE_PDC_SSC
->PDC_RNCR
= ISO15693_DMA_BUFFER_SIZE
; // DMA Next Counter registers
575 if (Handle15693SamplesFromTag(ci
, cq
, &DecodeTag
)) {
580 if(samples
> timeout
&& DecodeTag
.state
< STATE_TAG_RECEIVING_DATA
) {
589 if (DEBUG
) Dbprintf("max behindby = %d, samples = %d, gotFrame = %d, Decoder: state = %d, len = %d, bitCount = %d, posCount = %d",
590 maxBehindBy
, samples
, gotFrame
, DecodeTag
.state
, DecodeTag
.len
, DecodeTag
.bitCount
, DecodeTag
.posCount
);
592 if (tracing
&& DecodeTag
.len
> 0) {
593 LogTrace(DecodeTag
.output
, DecodeTag
.len
, 0, 0, NULL
, false);
596 return DecodeTag
.len
;
600 //=============================================================================
601 // An ISO15693 decoder for reader commands.
603 // This function is called 4 times per bit (every 2 subcarrier cycles).
604 // Subcarrier frequency fs is 848kHz, 1/fs = 1,18us, i.e. function is called every 2,36us
606 // LED B -> ON once we have received the SOF and are expecting the rest.
607 // LED B -> OFF once we have received EOF or are in error state or unsynced
609 // Returns: true if we received a EOF
610 // false if we are still waiting for some more
611 //=============================================================================
613 typedef struct DecodeReader
{
615 STATE_READER_UNSYNCD
,
616 STATE_READER_AWAIT_1ST_RISING_EDGE_OF_SOF
,
617 STATE_READER_AWAIT_2ND_FALLING_EDGE_OF_SOF
,
618 STATE_READER_AWAIT_2ND_RISING_EDGE_OF_SOF
,
619 STATE_READER_AWAIT_END_OF_SOF_1_OUT_OF_4
,
620 STATE_READER_RECEIVE_DATA_1_OUT_OF_4
,
621 STATE_READER_RECEIVE_DATA_1_OUT_OF_256
637 static int Handle15693SampleFromReader(uint8_t bit
, DecodeReader_t
* DecodeReader
)
639 switch(DecodeReader
->state
) {
640 case STATE_READER_UNSYNCD
:
642 // we went low, so this could be the beginning of a SOF
643 DecodeReader
->state
= STATE_READER_AWAIT_1ST_RISING_EDGE_OF_SOF
;
644 DecodeReader
->posCount
= 1;
648 case STATE_READER_AWAIT_1ST_RISING_EDGE_OF_SOF
:
649 DecodeReader
->posCount
++;
650 if(bit
) { // detected rising edge
651 if(DecodeReader
->posCount
< 4) { // rising edge too early (nominally expected at 5)
652 DecodeReader
->state
= STATE_READER_UNSYNCD
;
654 DecodeReader
->state
= STATE_READER_AWAIT_2ND_FALLING_EDGE_OF_SOF
;
657 if(DecodeReader
->posCount
> 5) { // stayed low for too long
658 DecodeReader
->state
= STATE_READER_UNSYNCD
;
660 // do nothing, keep waiting
665 case STATE_READER_AWAIT_2ND_FALLING_EDGE_OF_SOF
:
666 DecodeReader
->posCount
++;
667 if(!bit
) { // detected a falling edge
668 if (DecodeReader
->posCount
< 20) { // falling edge too early (nominally expected at 21 earliest)
669 DecodeReader
->state
= STATE_READER_UNSYNCD
;
670 } else if (DecodeReader
->posCount
< 23) { // SOF for 1 out of 4 coding
671 DecodeReader
->Coding
= CODING_1_OUT_OF_4
;
672 DecodeReader
->state
= STATE_READER_AWAIT_2ND_RISING_EDGE_OF_SOF
;
673 } else if (DecodeReader
->posCount
< 28) { // falling edge too early (nominally expected at 29 latest)
674 DecodeReader
->state
= STATE_READER_UNSYNCD
;
675 } else { // SOF for 1 out of 4 coding
676 DecodeReader
->Coding
= CODING_1_OUT_OF_256
;
677 DecodeReader
->state
= STATE_READER_AWAIT_2ND_RISING_EDGE_OF_SOF
;
680 if(DecodeReader
->posCount
> 29) { // stayed high for too long
681 DecodeReader
->state
= STATE_READER_UNSYNCD
;
683 // do nothing, keep waiting
688 case STATE_READER_AWAIT_2ND_RISING_EDGE_OF_SOF
:
689 DecodeReader
->posCount
++;
690 if (bit
) { // detected rising edge
691 if (DecodeReader
->Coding
== CODING_1_OUT_OF_256
) {
692 if (DecodeReader
->posCount
< 32) { // rising edge too early (nominally expected at 33)
693 DecodeReader
->state
= STATE_READER_UNSYNCD
;
695 DecodeReader
->posCount
= 1;
696 DecodeReader
->bitCount
= 0;
697 DecodeReader
->byteCount
= 0;
698 DecodeReader
->sum1
= 1;
699 DecodeReader
->state
= STATE_READER_RECEIVE_DATA_1_OUT_OF_256
;
702 } else { // CODING_1_OUT_OF_4
703 if (DecodeReader
->posCount
< 24) { // rising edge too early (nominally expected at 25)
704 DecodeReader
->state
= STATE_READER_UNSYNCD
;
706 DecodeReader
->state
= STATE_READER_AWAIT_END_OF_SOF_1_OUT_OF_4
;
710 if (DecodeReader
->Coding
== CODING_1_OUT_OF_256
) {
711 if (DecodeReader
->posCount
> 34) { // signal stayed low for too long
712 DecodeReader
->state
= STATE_READER_UNSYNCD
;
714 // do nothing, keep waiting
716 } else { // CODING_1_OUT_OF_4
717 if (DecodeReader
->posCount
> 26) { // signal stayed low for too long
718 DecodeReader
->state
= STATE_READER_UNSYNCD
;
720 // do nothing, keep waiting
726 case STATE_READER_AWAIT_END_OF_SOF_1_OUT_OF_4
:
727 DecodeReader
->posCount
++;
729 if (DecodeReader
->posCount
== 33) {
730 DecodeReader
->posCount
= 1;
731 DecodeReader
->bitCount
= 0;
732 DecodeReader
->byteCount
= 0;
733 DecodeReader
->sum1
= 1;
734 DecodeReader
->state
= STATE_READER_RECEIVE_DATA_1_OUT_OF_4
;
737 // do nothing, keep waiting
739 } else { // unexpected falling edge
740 DecodeReader
->state
= STATE_READER_UNSYNCD
;
744 case STATE_READER_RECEIVE_DATA_1_OUT_OF_4
:
745 DecodeReader
->posCount
++;
746 if (DecodeReader
->posCount
== 1) {
747 DecodeReader
->sum1
= bit
;
748 } else if (DecodeReader
->posCount
<= 4) {
749 DecodeReader
->sum1
+= bit
;
750 } else if (DecodeReader
->posCount
== 5) {
751 DecodeReader
->sum2
= bit
;
753 DecodeReader
->sum2
+= bit
;
755 if (DecodeReader
->posCount
== 8) {
756 DecodeReader
->posCount
= 0;
757 int corr10
= DecodeReader
->sum1
- DecodeReader
->sum2
;
758 int corr01
= DecodeReader
->sum2
- DecodeReader
->sum1
;
759 int corr11
= (DecodeReader
->sum1
+ DecodeReader
->sum2
) / 2;
760 if (corr01
> corr11
&& corr01
> corr10
) { // EOF
761 LED_B_OFF(); // Finished receiving
762 DecodeReader
->state
= STATE_READER_UNSYNCD
;
763 if (DecodeReader
->byteCount
!= 0) {
767 if (corr10
> corr11
) { // detected a 2bit position
768 DecodeReader
->shiftReg
>>= 2;
769 DecodeReader
->shiftReg
|= (DecodeReader
->bitCount
<< 6);
771 if (DecodeReader
->bitCount
== 15) { // we have a full byte
772 DecodeReader
->output
[DecodeReader
->byteCount
++] = DecodeReader
->shiftReg
;
773 if (DecodeReader
->byteCount
> DecodeReader
->byteCountMax
) {
774 // buffer overflow, give up
776 DecodeReader
->state
= STATE_READER_UNSYNCD
;
778 DecodeReader
->bitCount
= 0;
780 DecodeReader
->bitCount
++;
785 case STATE_READER_RECEIVE_DATA_1_OUT_OF_256
:
786 DecodeReader
->posCount
++;
787 if (DecodeReader
->posCount
== 1) {
788 DecodeReader
->sum1
= bit
;
789 } else if (DecodeReader
->posCount
<= 4) {
790 DecodeReader
->sum1
+= bit
;
791 } else if (DecodeReader
->posCount
== 5) {
792 DecodeReader
->sum2
= bit
;
794 DecodeReader
->sum2
+= bit
;
796 if (DecodeReader
->posCount
== 8) {
797 DecodeReader
->posCount
= 0;
798 int corr10
= DecodeReader
->sum1
- DecodeReader
->sum2
;
799 int corr01
= DecodeReader
->sum2
- DecodeReader
->sum1
;
800 int corr11
= (DecodeReader
->sum1
+ DecodeReader
->sum2
) / 2;
801 if (corr01
> corr11
&& corr01
> corr10
) { // EOF
802 LED_B_OFF(); // Finished receiving
803 DecodeReader
->state
= STATE_READER_UNSYNCD
;
804 if (DecodeReader
->byteCount
!= 0) {
808 if (corr10
> corr11
) { // detected the bit position
809 DecodeReader
->shiftReg
= DecodeReader
->bitCount
;
811 if (DecodeReader
->bitCount
== 255) { // we have a full byte
812 DecodeReader
->output
[DecodeReader
->byteCount
++] = DecodeReader
->shiftReg
;
813 if (DecodeReader
->byteCount
> DecodeReader
->byteCountMax
) {
814 // buffer overflow, give up
816 DecodeReader
->state
= STATE_READER_UNSYNCD
;
819 DecodeReader
->bitCount
++;
825 DecodeReader
->state
= STATE_READER_UNSYNCD
;
833 static void DecodeReaderInit(uint8_t *data
, uint16_t max_len
, DecodeReader_t
* DecodeReader
)
835 DecodeReader
->output
= data
;
836 DecodeReader
->byteCountMax
= max_len
;
837 DecodeReader
->state
= STATE_READER_UNSYNCD
;
838 DecodeReader
->byteCount
= 0;
839 DecodeReader
->bitCount
= 0;
840 DecodeReader
->shiftReg
= 0;
844 //-----------------------------------------------------------------------------
845 // Receive a command (from the reader to us, where we are the simulated tag),
846 // and store it in the given buffer, up to the given maximum length. Keeps
847 // spinning, waiting for a well-framed command, until either we get one
848 // (returns true) or someone presses the pushbutton on the board (false).
850 // Assume that we're called with the SSC (to the FPGA) and ADC path set
852 //-----------------------------------------------------------------------------
854 static int GetIso15693CommandFromReader(uint8_t *received
, size_t max_len
, uint32_t *eof_time
)
857 int lastRxCounter
, samples
= 0;
858 bool gotFrame
= false;
861 uint8_t dmaBuf
[ISO15693_DMA_BUFFER_SIZE
];
863 // the decoder data structure
864 DecodeReader_t DecodeReader
;
865 DecodeReaderInit(received
, max_len
, &DecodeReader
);
867 // wait for last transfer to complete
868 while (!(AT91C_BASE_SSC
->SSC_SR
& AT91C_SSC_TXEMPTY
));
871 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR
| FPGA_HF_SIMULATOR_NO_MODULATION
);
873 // clear receive register and wait for next transfer
874 uint32_t temp
= AT91C_BASE_SSC
->SSC_RHR
;
876 while (!(AT91C_BASE_SSC
->SSC_SR
& AT91C_SSC_RXRDY
)) ;
878 uint32_t bit_time
= GetCountSspClk() & 0xfffffff8;
880 // Setup and start DMA.
881 FpgaSetupSscDma(dmaBuf
, ISO15693_DMA_BUFFER_SIZE
);
882 uint8_t *upTo
= dmaBuf
;
883 lastRxCounter
= ISO15693_DMA_BUFFER_SIZE
;
886 int behindBy
= (lastRxCounter
- AT91C_BASE_PDC_SSC
->PDC_RCR
) & (ISO15693_DMA_BUFFER_SIZE
-1);
887 if(behindBy
> maxBehindBy
) {
888 maxBehindBy
= behindBy
;
891 if (behindBy
< 1) continue;
895 if(upTo
>= dmaBuf
+ ISO15693_DMA_BUFFER_SIZE
) { // we have read all of the DMA buffer content.
896 upTo
= dmaBuf
; // start reading the circular buffer from the beginning
897 lastRxCounter
+= ISO15693_DMA_BUFFER_SIZE
;
899 if (AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_ENDRX
)) { // DMA Counter Register had reached 0, already rotated.
900 AT91C_BASE_PDC_SSC
->PDC_RNPR
= (uint32_t) dmaBuf
; // refresh the DMA Next Buffer and
901 AT91C_BASE_PDC_SSC
->PDC_RNCR
= ISO15693_DMA_BUFFER_SIZE
; // DMA Next Counter registers
904 for (int i
= 7; i
>= 0; i
--) {
905 if (Handle15693SampleFromReader((b
>> i
) & 0x01, &DecodeReader
)) {
906 *eof_time
= bit_time
+ samples
- DELAY_READER_TO_ARM
; // end of EOF
917 if (BUTTON_PRESS()) {
918 DecodeReader
.byteCount
= 0;
928 if (DEBUG
) Dbprintf("max behindby = %d, samples = %d, gotFrame = %d, Decoder: state = %d, len = %d, bitCount = %d, posCount = %d",
929 maxBehindBy
, samples
, gotFrame
, DecodeReader
.state
, DecodeReader
.byteCount
, DecodeReader
.bitCount
, DecodeReader
.posCount
);
931 if (tracing
&& DecodeReader
.byteCount
> 0) {
932 LogTrace(DecodeReader
.output
, DecodeReader
.byteCount
, 0, 0, NULL
, true);
935 return DecodeReader
.byteCount
;
939 static void BuildIdentifyRequest(void);
940 //-----------------------------------------------------------------------------
941 // Start to read an ISO 15693 tag. We send an identify request, then wait
942 // for the response. The response is not demodulated, just left in the buffer
943 // so that it can be downloaded to a PC and processed there.
944 //-----------------------------------------------------------------------------
945 void AcquireRawAdcSamplesIso15693(void)
950 uint8_t *dest
= BigBuf_get_addr();
952 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
953 BuildIdentifyRequest();
955 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
957 // Give the tags time to energize
959 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
962 // Now send the command
963 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_TX
);
964 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX
);
967 for(int c
= 0; c
< ToSendMax
; ) {
968 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
)) {
969 AT91C_BASE_SSC
->SSC_THR
= ~ToSend
[c
];
976 // wait for last transfer to complete
977 while (!(AT91C_BASE_SSC
->SSC_SR
& AT91C_SSC_TXEMPTY
));
979 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
980 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
982 for(int c
= 0; c
< 4000; ) {
983 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
984 uint16_t iq
= AT91C_BASE_SSC
->SSC_RHR
;
985 // The samples are correlations against I and Q versions of the
986 // tone that the tag AM-modulates. We just want power,
987 // so abs(I) + abs(Q) is close to what we want.
988 int8_t i
= (int8_t)(iq
>> 8);
989 int8_t q
= (int8_t)(iq
& 0xff);
990 uint8_t r
= AMPLITUDE(i
, q
);
995 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1000 // TODO: there is no trigger condition. The 14000 samples represent a time frame of 66ms.
1001 // It is unlikely that we get something meaningful.
1002 // TODO: Currently we only record tag answers. Add tracing of reader commands.
1003 // TODO: would we get something at all? The carrier is switched on...
1004 void RecordRawAdcSamplesIso15693(void)
1009 uint8_t *dest
= BigBuf_get_addr();
1011 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
1013 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
1015 // Start from off (no field generated)
1016 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1019 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
1024 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
1026 for(int c
= 0; c
< 14000;) {
1027 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
1028 uint16_t iq
= AT91C_BASE_SSC
->SSC_RHR
;
1029 // The samples are correlations against I and Q versions of the
1030 // tone that the tag AM-modulates. We just want power,
1031 // so abs(I) + abs(Q) is close to what we want.
1032 int8_t i
= (int8_t)(iq
>> 8);
1033 int8_t q
= (int8_t)(iq
& 0xff);
1034 uint8_t r
= AMPLITUDE(i
, q
);
1039 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1041 Dbprintf("finished recording");
1046 // Initialize the proxmark as iso15k reader
1047 // (this might produces glitches that confuse some tags
1048 static void Iso15693InitReader() {
1049 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
1053 // Start from off (no field generated)
1055 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1058 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
1059 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
1061 // Give the tags time to energize
1063 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
1067 ///////////////////////////////////////////////////////////////////////
1068 // ISO 15693 Part 3 - Air Interface
1069 // This section basically contains transmission and receiving of bits
1070 ///////////////////////////////////////////////////////////////////////
1072 // Encode (into the ToSend buffers) an identify request, which is the first
1073 // thing that you must send to a tag to get a response.
1074 static void BuildIdentifyRequest(void)
1079 // one sub-carrier, inventory, 1 slot, fast rate
1080 // AFI is at bit 5 (1<<4) when doing an INVENTORY
1081 cmd
[0] = (1 << 2) | (1 << 5) | (1 << 1);
1082 // inventory command code
1088 cmd
[3] = crc
& 0xff;
1091 CodeIso15693AsReader(cmd
, sizeof(cmd
));
1094 // uid is in transmission order (which is reverse of display order)
1095 static void BuildReadBlockRequest(uint8_t *uid
, uint8_t blockNumber
)
1100 // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
1101 // followed by teh block data
1102 // one sub-carrier, inventory, 1 slot, fast rate
1103 cmd
[0] = (1 << 6)| (1 << 5) | (1 << 1); // no SELECT bit, ADDR bit, OPTION bit
1104 // READ BLOCK command code
1106 // UID may be optionally specified here
1115 cmd
[9] = uid
[7]; // 0xe0; // always e0 (not exactly unique)
1116 // Block number to read
1117 cmd
[10] = blockNumber
;//0x00;
1119 crc
= Crc(cmd
, 11); // the crc needs to be calculated over 11 bytes
1120 cmd
[11] = crc
& 0xff;
1123 CodeIso15693AsReader(cmd
, sizeof(cmd
));
1127 // Now the VICC>VCD responses when we are simulating a tag
1128 static void BuildInventoryResponse(uint8_t *uid
)
1134 cmd
[0] = 0; // No error, no protocol format extension
1135 cmd
[1] = 0; // DSFID (data storage format identifier). 0x00 = not supported
1137 cmd
[2] = uid
[7]; //0x32;
1138 cmd
[3] = uid
[6]; //0x4b;
1139 cmd
[4] = uid
[5]; //0x03;
1140 cmd
[5] = uid
[4]; //0x01;
1141 cmd
[6] = uid
[3]; //0x00;
1142 cmd
[7] = uid
[2]; //0x10;
1143 cmd
[8] = uid
[1]; //0x05;
1144 cmd
[9] = uid
[0]; //0xe0;
1147 cmd
[10] = crc
& 0xff;
1150 CodeIso15693AsTag(cmd
, sizeof(cmd
));
1153 // Universal Method for sending to and recv bytes from a tag
1154 // init ... should we initialize the reader?
1155 // speed ... 0 low speed, 1 hi speed
1156 // **recv will return you a pointer to the received data
1157 // If you do not need the answer use NULL for *recv[]
1158 // return: lenght of received data
1159 int SendDataTag(uint8_t *send
, int sendlen
, bool init
, int speed
, uint8_t **recv
) {
1165 if (init
) Iso15693InitReader();
1168 uint8_t *answer
= BigBuf_get_addr() + 4000;
1169 if (recv
!= NULL
) memset(answer
, 0, 100);
1172 // low speed (1 out of 256)
1173 CodeIso15693AsReader256(send
, sendlen
);
1175 // high speed (1 out of 4)
1176 CodeIso15693AsReader(send
, sendlen
);
1179 TransmitTo15693Tag(ToSend
,ToSendMax
);
1180 // Now wait for a response
1182 answerLen
= GetIso15693AnswerFromTag(answer
, 100);
1192 // --------------------------------------------------------------------
1194 // --------------------------------------------------------------------
1196 // Decodes a message from a tag and displays its metadata and content
1197 #define DBD15STATLEN 48
1198 void DbdecodeIso15693Answer(int len
, uint8_t *d
) {
1199 char status
[DBD15STATLEN
+1]={0};
1204 strncat(status
,"ProtExt ",DBD15STATLEN
);
1207 strncat(status
,"Error ",DBD15STATLEN
);
1210 strncat(status
,"01:notSupp",DBD15STATLEN
);
1213 strncat(status
,"02:notRecog",DBD15STATLEN
);
1216 strncat(status
,"03:optNotSupp",DBD15STATLEN
);
1219 strncat(status
,"0f:noInfo",DBD15STATLEN
);
1222 strncat(status
,"10:dontExist",DBD15STATLEN
);
1225 strncat(status
,"11:lockAgain",DBD15STATLEN
);
1228 strncat(status
,"12:locked",DBD15STATLEN
);
1231 strncat(status
,"13:progErr",DBD15STATLEN
);
1234 strncat(status
,"14:lockErr",DBD15STATLEN
);
1237 strncat(status
,"unknownErr",DBD15STATLEN
);
1239 strncat(status
," ",DBD15STATLEN
);
1241 strncat(status
,"NoErr ",DBD15STATLEN
);
1245 if ( (( crc
& 0xff ) == d
[len
-2]) && (( crc
>> 8 ) == d
[len
-1]) )
1246 strncat(status
,"CrcOK",DBD15STATLEN
);
1248 strncat(status
,"CrcFail!",DBD15STATLEN
);
1250 Dbprintf("%s",status
);
1256 ///////////////////////////////////////////////////////////////////////
1257 // Functions called via USB/Client
1258 ///////////////////////////////////////////////////////////////////////
1260 void SetDebugIso15693(uint32_t debug
) {
1262 Dbprintf("Iso15693 Debug is now %s",DEBUG
?"on":"off");
1266 //-----------------------------------------------------------------------------
1267 // Simulate an ISO15693 reader, perform anti-collision and then attempt to read a sector
1268 // all demodulation performed in arm rather than host. - greg
1269 //-----------------------------------------------------------------------------
1270 void ReaderIso15693(uint32_t parameter
)
1276 uint8_t TagUID
[8] = {0x00};
1278 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
1280 uint8_t *answer1
= BigBuf_get_addr() + 4000;
1281 memset(answer1
, 0x00, 200);
1283 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
1285 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
1287 // Start from off (no field generated)
1288 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1291 // Give the tags time to energize
1293 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
1296 // FIRST WE RUN AN INVENTORY TO GET THE TAG UID
1297 // THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME
1299 // Now send the IDENTIFY command
1300 BuildIdentifyRequest();
1302 TransmitTo15693Tag(ToSend
,ToSendMax
);
1304 // Now wait for a response
1305 answerLen1
= GetIso15693AnswerFromTag(answer1
, 100) ;
1307 if (answerLen1
>=12) // we should do a better check than this
1309 TagUID
[0] = answer1
[2];
1310 TagUID
[1] = answer1
[3];
1311 TagUID
[2] = answer1
[4];
1312 TagUID
[3] = answer1
[5];
1313 TagUID
[4] = answer1
[6];
1314 TagUID
[5] = answer1
[7];
1315 TagUID
[6] = answer1
[8]; // IC Manufacturer code
1316 TagUID
[7] = answer1
[9]; // always E0
1320 Dbprintf("%d octets read from IDENTIFY request:", answerLen1
);
1321 DbdecodeIso15693Answer(answerLen1
, answer1
);
1322 Dbhexdump(answerLen1
, answer1
, false);
1325 if (answerLen1
>= 12)
1326 Dbprintf("UID = %02hX%02hX%02hX%02hX%02hX%02hX%02hX%02hX",
1327 TagUID
[7],TagUID
[6],TagUID
[5],TagUID
[4],
1328 TagUID
[3],TagUID
[2],TagUID
[1],TagUID
[0]);
1331 // Dbprintf("%d octets read from SELECT request:", answerLen2);
1332 // DbdecodeIso15693Answer(answerLen2,answer2);
1333 // Dbhexdump(answerLen2,answer2,true);
1335 // Dbprintf("%d octets read from XXX request:", answerLen3);
1336 // DbdecodeIso15693Answer(answerLen3,answer3);
1337 // Dbhexdump(answerLen3,answer3,true);
1340 if (answerLen1
>= 12 && DEBUG
) {
1341 uint8_t *answer2
= BigBuf_get_addr() + 4100;
1343 while (i
< 32) { // sanity check, assume max 32 pages
1344 BuildReadBlockRequest(TagUID
, i
);
1345 TransmitTo15693Tag(ToSend
, ToSendMax
);
1346 int answerLen2
= GetIso15693AnswerFromTag(answer2
, 100);
1347 if (answerLen2
> 0) {
1348 Dbprintf("READ SINGLE BLOCK %d returned %d octets:", i
, answerLen2
);
1349 DbdecodeIso15693Answer(answerLen2
, answer2
);
1350 Dbhexdump(answerLen2
, answer2
, false);
1351 if ( *((uint32_t*) answer2
) == 0x07160101 ) break; // exit on NoPageErr
1357 // for the time being, switch field off to protect rdv4.0
1358 // note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway
1359 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1366 // Simulate an ISO15693 TAG.
1367 // For Inventory command: print command and send Inventory Response with given UID
1368 // TODO: interpret other reader commands and send appropriate response
1369 void SimTagIso15693(uint32_t parameter
, uint8_t *uid
)
1374 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
1375 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
1376 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR
| FPGA_HF_SIMULATOR_NO_MODULATION
);
1377 FpgaSetupSsc(FPGA_MAJOR_MODE_HF_SIMULATOR
);
1381 uint8_t cmd
[ISO15693_MAX_COMMAND_LENGTH
];
1383 // Build a suitable response to the reader INVENTORY command
1384 BuildInventoryResponse(uid
);
1387 while (!BUTTON_PRESS()) {
1388 uint32_t eof_time
= 0, start_time
= 0;
1389 int cmd_len
= GetIso15693CommandFromReader(cmd
, sizeof(cmd
), &eof_time
);
1391 if ((cmd_len
>= 5) && (cmd
[0] & ISO15693_REQ_INVENTORY
) && (cmd
[1] == ISO15693_INVENTORY
)) { // TODO: check more flags
1392 bool slow
= !(cmd
[0] & ISO15693_REQ_DATARATE_HIGH
);
1393 start_time
= eof_time
+ DELAY_ISO15693_VCD_TO_VICC
- DELAY_ARM_TO_READER
;
1394 TransmitTo15693Reader(ToSend
, ToSendMax
, start_time
, slow
);
1397 Dbprintf("%d bytes read from reader:", cmd_len
);
1398 Dbhexdump(cmd_len
, cmd
, false);
1405 // Since there is no standardized way of reading the AFI out of a tag, we will brute force it
1406 // (some manufactures offer a way to read the AFI, though)
1407 void BruteforceIso15693Afi(uint32_t speed
)
1414 int datalen
=0, recvlen
=0;
1416 Iso15693InitReader();
1418 // first without AFI
1419 // Tags should respond without AFI and with AFI=0 even when AFI is active
1421 data
[0] = ISO15693_REQ_DATARATE_HIGH
| ISO15693_REQ_INVENTORY
| ISO15693_REQINV_SLOT1
;
1422 data
[1] = ISO15693_INVENTORY
;
1423 data
[2] = 0; // mask length
1424 datalen
= AddCrc(data
,3);
1425 recvlen
= SendDataTag(data
, datalen
, false, speed
, &recv
);
1428 Dbprintf("NoAFI UID=%s",sprintUID(NULL
,&recv
[2]));
1433 data
[0] = ISO15693_REQ_DATARATE_HIGH
| ISO15693_REQ_INVENTORY
| ISO15693_REQINV_AFI
| ISO15693_REQINV_SLOT1
;
1434 data
[1] = ISO15693_INVENTORY
;
1436 data
[3] = 0; // mask length
1438 for (int i
=0;i
<256;i
++) {
1440 datalen
=AddCrc(data
,4);
1441 recvlen
=SendDataTag(data
, datalen
, false, speed
, &recv
);
1444 Dbprintf("AFI=%i UID=%s", i
, sprintUID(NULL
,&recv
[2]));
1447 Dbprintf("AFI Bruteforcing done.");
1449 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1453 // Allows to directly send commands to the tag via the client
1454 void DirectTag15693Command(uint32_t datalen
, uint32_t speed
, uint32_t recv
, uint8_t data
[]) {
1457 uint8_t *recvbuf
= BigBuf_get_addr();
1463 Dbhexdump(datalen
, data
, false);
1466 recvlen
= SendDataTag(data
, datalen
, true, speed
, (recv
?&recvbuf
:NULL
));
1469 cmd_send(CMD_ACK
, recvlen
>48?48:recvlen
, 0, 0, recvbuf
, 48);
1473 DbdecodeIso15693Answer(recvlen
,recvbuf
);
1474 Dbhexdump(recvlen
, recvbuf
, false);
1478 // for the time being, switch field off to protect rdv4.0
1479 // note: this prevents using hf 15 cmd with s option - which isn't implemented yet anyway
1480 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1489 // --------------------------------------------------------------------
1490 // -- Misc & deprecated functions
1491 // --------------------------------------------------------------------
1495 // do not use; has a fix UID
1496 static void __attribute__((unused)) BuildSysInfoRequest(uint8_t *uid)
1501 // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
1502 // followed by teh block data
1503 // one sub-carrier, inventory, 1 slot, fast rate
1504 cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
1505 // System Information command code
1507 // UID may be optionally specified here
1516 cmd[9]= 0xe0; // always e0 (not exactly unique)
1518 crc = Crc(cmd, 10); // the crc needs to be calculated over 2 bytes
1519 cmd[10] = crc & 0xff;
1522 CodeIso15693AsReader(cmd, sizeof(cmd));
1526 // do not use; has a fix UID
1527 static void __attribute__((unused)) BuildReadMultiBlockRequest(uint8_t *uid)
1532 // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
1533 // followed by teh block data
1534 // one sub-carrier, inventory, 1 slot, fast rate
1535 cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
1536 // READ Multi BLOCK command code
1538 // UID may be optionally specified here
1547 cmd[9]= 0xe0; // always e0 (not exactly unique)
1548 // First Block number to read
1550 // Number of Blocks to read
1551 cmd[11] = 0x2f; // read quite a few
1553 crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
1554 cmd[12] = crc & 0xff;
1557 CodeIso15693AsReader(cmd, sizeof(cmd));
1560 // do not use; has a fix UID
1561 static void __attribute__((unused)) BuildArbitraryRequest(uint8_t *uid,uint8_t CmdCode)
1566 // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
1567 // followed by teh block data
1568 // one sub-carrier, inventory, 1 slot, fast rate
1569 cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
1570 // READ BLOCK command code
1572 // UID may be optionally specified here
1581 cmd[9]= 0xe0; // always e0 (not exactly unique)
1587 // cmd[13] = 0x00; //Now the CRC
1588 crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
1589 cmd[12] = crc & 0xff;
1592 CodeIso15693AsReader(cmd, sizeof(cmd));
1595 // do not use; has a fix UID
1596 static void __attribute__((unused)) BuildArbitraryCustomRequest(uint8_t uid[], uint8_t CmdCode)
1601 // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
1602 // followed by teh block data
1603 // one sub-carrier, inventory, 1 slot, fast rate
1604 cmd[0] = (1 << 5) | (1 << 1); // no SELECT bit
1605 // READ BLOCK command code
1607 // UID may be optionally specified here
1616 cmd[9]= 0xe0; // always e0 (not exactly unique)
1618 cmd[10] = 0x05; // for custom codes this must be manufcturer code
1622 // cmd[13] = 0x00; //Now the CRC
1623 crc = Crc(cmd, 12); // the crc needs to be calculated over 2 bytes
1624 cmd[12] = crc & 0xff;
1627 CodeIso15693AsReader(cmd, sizeof(cmd));