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
6 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
7 // at your option, any later version. See the LICENSE.txt file for the text of
9 //-----------------------------------------------------------------------------
10 // Routines to support ISO 15693. This includes both the reader software and
11 // the `fake tag' modes, but at the moment I've implemented only the reader
12 // stuff, and that barely.
13 // Modified to perform modulation onboard in arm rather than on PC
14 // Also added additional reader commands (SELECT, READ etc.)
15 //-----------------------------------------------------------------------------
16 // The ISO 15693 describes two transmission modes from reader to tag, and 4
17 // transmission modes from tag to reader. As of Mar 2010 this code only
18 // supports one of each: "1of4" mode from reader to tag, and the highspeed
19 // variant with one subcarrier from card to reader.
20 // As long, as the card fully support ISO 15693 this is no problem, since the
21 // reader chooses both data rates, but some non-standard tags do not. Further for
22 // the simulation to work, we will need to support all data rates.
24 // VCD (reader) -> VICC (tag)
26 // data rate: 1,66 kbit/s (fc/8192)
27 // used for long range
29 // data rate: 26,48 kbit/s (fc/512)
30 // used for short range, high speed
32 // VICC (tag) -> VCD (reader)
34 // ASK / one subcarrier (423,75 khz)
35 // FSK / two subcarriers (423,75 khz && 484,28 khz)
36 // Data Rates / Modes:
37 // low ASK: 6,62 kbit/s
38 // low FSK: 6.67 kbit/s
39 // high ASK: 26,48 kbit/s
40 // high FSK: 26,69 kbit/s
41 //-----------------------------------------------------------------------------
42 // added "1 out of 256" mode (for VCD->PICC) - atrox 20100911
46 // *) UID is always used "transmission order" (LSB), which is reverse to display order
48 // TODO / BUGS / ISSUES:
49 // *) writing to tags takes longer: we miss the answer from the tag in most cases
50 // -> tweak the read-timeout times
51 // *) signal decoding from the card is still a bit shaky.
52 // *) signal decoding is unable to detect collissions.
53 // *) add anti-collission support for inventory-commands
54 // *) read security status of a block
55 // *) sniffing and simulation do only support one transmission mode. need to support
56 // all 8 transmission combinations
57 // *) remove or refactor code under "depricated"
58 // *) document all the functions
61 #include "proxmark3.h"
65 #include "iso15693tools.h"
68 ///////////////////////////////////////////////////////////////////////
69 // ISO 15693 Part 2 - Air Interface
70 // This section basicly contains transmission and receiving of bits
71 ///////////////////////////////////////////////////////////////////////
73 #define FrameSOF Iso15693FrameSOF
74 #define Logic0 Iso15693Logic0
75 #define Logic1 Iso15693Logic1
76 #define FrameEOF Iso15693FrameEOF
78 #define Crc(data,datalen) Iso15693Crc(data,datalen)
79 #define AddCrc(data,datalen) Iso15693AddCrc(data,datalen)
80 #define sprintUID(target,uid) Iso15693sprintUID(target,uid)
85 // ---------------------------
87 // ---------------------------
89 // prepare data using "1 out of 4" code for later transmission
90 // resulting data rate is 26,48 kbit/s (fc/512)
92 // n ... length of data
93 static void CodeIso15693AsReader(uint8_t *cmd
, int n
)
99 // Give it a bit of slack at the beginning
100 for(i
= 0; i
< 24; i
++)
112 for(i
= 0; i
< n
; i
++) {
113 for(j
= 0; j
< 8; j
+= 2) {
114 int these
= (cmd
[i
] >> j
) & 3;
165 // And slack at the end, too.
166 for(i
= 0; i
< 24; i
++)
170 // encode data using "1 out of 256" sheme
171 // data rate is 1,66 kbit/s (fc/8192)
172 // is designed for more robust communication over longer distances
173 static void CodeIso15693AsReader256(uint8_t *cmd
, int n
)
179 // Give it a bit of slack at the beginning
180 for(i
= 0; i
< 24; i
++)
193 for(i
= 0; i
< n
; i
++) {
194 for (j
= 0; j
<= 255; j
++) {
210 // And slack at the end, too.
211 for(i
= 0; i
< 24; i
++)
216 // Transmit the command (to the tag) that was placed in ToSend[].
217 static void TransmitTo15693Tag(const uint8_t *cmd
, int len
, int *samples
, int *wait
)
221 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX
);
222 if(*wait
< 10) { *wait
= 10; }
224 // for(c = 0; c < *wait;) {
225 // if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
226 // AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing!
229 // if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
230 // r = AT91C_BASE_SSC->SSC_RHR;
238 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
)) {
239 AT91C_BASE_SSC
->SSC_THR
= cmd
[c
];
240 if( ++c
>= len
) break;
242 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
243 r
= AT91C_BASE_SSC
->SSC_RHR
;
248 *samples
= (c
+ *wait
) << 3;
251 //-----------------------------------------------------------------------------
252 // Transmit the command (to the reader) that was placed in ToSend[].
253 //-----------------------------------------------------------------------------
254 static void TransmitTo15693Reader(const uint8_t *cmd
, int len
, int *samples
, int *wait
)
258 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR
|FPGA_HF_SIMULATOR_MODULATE_424K
);
259 if(*wait
< 10) { *wait
= 10; }
262 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
)) {
263 AT91C_BASE_SSC
->SSC_THR
= cmd
[c
];
264 if( ++c
>= len
) break;
266 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
267 r
= AT91C_BASE_SSC
->SSC_RHR
;
272 *samples
= (c
+ *wait
) << 3;
283 // number of decoded bytes
284 static int GetIso15693AnswerFromTag(uint8_t *receivedResponse
, int maxLen
, int *samples
, int *elapsed
)
286 uint8_t *dest
= BigBuf_get_addr();
288 int c
= 0, getNext
= FALSE
;
291 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
292 SpinDelay(100); // greg - experiment to get rid of some of the 0 byte/failed reads
295 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
))
296 AT91C_BASE_SSC
->SSC_THR
= 0x43;
298 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
300 b
= (int8_t)AT91C_BASE_SSC
->SSC_RHR
;
302 // The samples are correlations against I and Q versions of the
303 // tone that the tag AM-modulates, so every other sample is I,
304 // every other is Q. We just want power, so abs(I) + abs(Q) is
305 // close to what we want.
306 // iceman 2016, amplitude sqrt(abs(i) + abs(q))
308 dest
[c
++] = (uint8_t)ABS(b
) + ABS(prev
);
320 //////////////////////////////////////////
321 /////////// DEMODULATE ///////////////////
322 //////////////////////////////////////////
325 int max
= 0, maxPos
=0, skip
= 4;
326 int k
= 0; // this will be our return value
328 // if(GraphTraceLen < 1000) return; // THIS CHECKS FOR A BUFFER TO SMALL
330 // First, correlate for SOF
331 for(i
= 0; i
< 100; i
++) {
333 for(j
= 0; j
< ARRAYLEN(FrameSOF
); j
+= skip
) {
334 corr
+= FrameSOF
[j
] * dest
[i
+(j
/skip
)];
341 // DbpString("SOF at %d, correlation %d", maxPos,max/(ARRAYLEN(FrameSOF)/skip));
343 // greg - If correlation is less than 1 then there's little point in continuing
344 if ((max
/(ARRAYLEN(FrameSOF
)/skip
)) >= 1)
346 i
= maxPos
+ ARRAYLEN(FrameSOF
) / skip
;
349 memset(outBuf
, 0, sizeof(outBuf
));
352 int corr0
= 0, corr1
= 0, corrEOF
= 0;
353 for(j
= 0; j
< ARRAYLEN(Logic0
); j
+= skip
) {
354 corr0
+= Logic0
[j
] * dest
[i
+(j
/skip
)];
356 for(j
= 0; j
< ARRAYLEN(Logic1
); j
+= skip
) {
357 corr1
+= Logic1
[j
] * dest
[i
+(j
/skip
)];
359 for(j
= 0; j
< ARRAYLEN(FrameEOF
); j
+= skip
) {
360 corrEOF
+= FrameEOF
[j
] * dest
[i
+(j
/skip
)];
362 // Even things out by the length of the target waveform.
366 if(corrEOF
> corr1
&& corrEOF
> corr0
) {
367 // DbpString("EOF at %d", i);
369 } else if(corr1
> corr0
) {
370 i
+= ARRAYLEN(Logic1
)/skip
;
373 i
+= ARRAYLEN(Logic0
)/skip
;
380 if( ( i
+ (int)ARRAYLEN(FrameEOF
)) >= 2000) {
381 DbpString("ran off end!");
385 if(mask
!= 0x01) { // this happens, when we miss the EOF
386 // TODO: for some reason this happens quite often
387 if (DEBUG
) Dbprintf("error, uneven octet! (extra bits!) mask=%02x", mask
);
388 if (mask
< 0x08) k
--; // discard the last uneven octet;
389 // 0x08 is an assumption - but works quite often
393 // strncat(str1," octets read",8);
395 // DbpString( str1); // DbpString("%d octets", k);
397 // for(i = 0; i < k; i+=3) {
398 // //DbpString("# %2d: %02x ", i, outBuf[i]);
399 // DbpIntegers(outBuf[i],outBuf[i+1],outBuf[i+2]);
402 for(i
= 0; i
< k
; i
++) {
403 receivedResponse
[i
] = outBuf
[i
];
405 } // "end if correlation > 0" (max/(ARRAYLEN(FrameSOF)/skip))
406 return k
; // return the number of bytes demodulated
410 // Now the GetISO15693 message from sniffing command
411 static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse
, int maxLen
, int *samples
, int *elapsed
)
413 uint8_t *dest
= BigBuf_get_addr();
415 int c
= 0, getNext
= FALSE
;
418 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
419 SpinDelay(100); // greg - experiment to get rid of some of the 0 byte/failed reads
422 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
))
423 AT91C_BASE_SSC
->SSC_THR
= 0x43;
425 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
426 int8_t b
= (int8_t)AT91C_BASE_SSC
->SSC_RHR
;
428 // The samples are correlations against I and Q versions of the
429 // tone that the tag AM-modulates, so every other sample is I,
430 // every other is Q. We just want power, so abs(I) + abs(Q) is
431 // close to what we want.
433 dest
[c
++] = (uint8_t)ABS(b
) + ABS(prev
);
444 //////////////////////////////////////////
445 /////////// DEMODULATE ///////////////////
446 //////////////////////////////////////////
448 int i
, j
, max
= 0, maxPos
=0, skip
= 4;
450 // First, correlate for SOF
451 for(i
= 0; i
< 19000; i
++) {
453 for(j
= 0; j
< ARRAYLEN(FrameSOF
); j
+= skip
) {
454 corr
+= FrameSOF
[j
]*dest
[i
+(j
/skip
)];
461 // DbpString("SOF at %d, correlation %d", maxPos,max/(ARRAYLEN(FrameSOF)/skip));
463 int k
= 0; // this will be our return value
465 // greg - If correlation is less than 1 then there's little point in continuing
466 if ((max
/(ARRAYLEN(FrameSOF
)/skip
)) >= 1) // THIS SHOULD BE 1
469 i
= maxPos
+ ARRAYLEN(FrameSOF
)/skip
;
472 memset(outBuf
, 0, sizeof(outBuf
));
475 int corr0
= 0, corr1
= 0, corrEOF
= 0;
476 for(j
= 0; j
< ARRAYLEN(Logic0
); j
+= skip
) {
477 corr0
+= Logic0
[j
]*dest
[i
+(j
/skip
)];
479 for(j
= 0; j
< ARRAYLEN(Logic1
); j
+= skip
) {
480 corr1
+= Logic1
[j
]*dest
[i
+(j
/skip
)];
482 for(j
= 0; j
< ARRAYLEN(FrameEOF
); j
+= skip
) {
483 corrEOF
+= FrameEOF
[j
]*dest
[i
+(j
/skip
)];
485 // Even things out by the length of the target waveform.
489 if(corrEOF
> corr1
&& corrEOF
> corr0
) {
490 // DbpString("EOF at %d", i);
492 } else if(corr1
> corr0
) {
493 i
+= ARRAYLEN(Logic1
)/skip
;
496 i
+= ARRAYLEN(Logic0
)/skip
;
503 if((i
+(int)ARRAYLEN(FrameEOF
)) >= 2000) {
504 DbpString("ran off end!");
509 DbpString("sniff: error, uneven octet! (discard extra bits!)");
510 // DbpString(" mask=%02x", mask);
514 // strncat(str1," octets read",8);
516 // DbpString( str1); // DbpString("%d octets", k);
518 // for(i = 0; i < k; i+=3) {
519 // //DbpString("# %2d: %02x ", i, outBuf[i]);
520 // DbpIntegers(outBuf[i],outBuf[i+1],outBuf[i+2]);
523 for(i
= 0; i
< k
; i
++) {
524 receivedResponse
[i
] = outBuf
[i
];
526 } // "end if correlation > 0" (max/(ARRAYLEN(FrameSOF)/skip))
527 return k
; // return the number of bytes demodulated
531 static void BuildIdentifyRequest(void);
532 //-----------------------------------------------------------------------------
533 // Start to read an ISO 15693 tag. We send an identify request, then wait
534 // for the response. The response is not demodulated, just left in the buffer
535 // so that it can be downloaded to a PC and processed there.
536 //-----------------------------------------------------------------------------
537 void AcquireRawAdcSamplesIso15693(void)
539 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
541 int c
= 0, getNext
= FALSE
;
545 uint8_t *dest
= BigBuf_get_addr();
546 BuildIdentifyRequest();
548 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
550 // Give the tags time to energize
551 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
554 // Now send the command
556 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX
);
560 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
)) {
561 AT91C_BASE_SSC
->SSC_THR
= ToSend
[c
];
562 if( ++c
== ToSendMax
+3) break;
564 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
565 r
= AT91C_BASE_SSC
->SSC_RHR
;
571 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
575 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
))
576 AT91C_BASE_SSC
->SSC_THR
= 0x43;
578 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
580 int8_t b
= (int8_t)AT91C_BASE_SSC
->SSC_RHR
;
582 // The samples are correlations against I and Q versions of the
583 // tone that the tag AM-modulates, so every other sample is I,
584 // every other is Q. We just want power, so abs(I) + abs(Q) is
585 // close to what we want.
588 dest
[c
++] = (uint8_t)(ABS(b
) + ABS(prev
));
601 void RecordRawAdcSamplesIso15693(void)
603 uint8_t *dest
= BigBuf_get_addr();
605 int c
= 0, getNext
= FALSE
;
608 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
612 // Start from off (no field generated)
613 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
616 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
619 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
622 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_TXRDY
)) {
623 AT91C_BASE_SSC
->SSC_THR
= 0x43;
625 if(AT91C_BASE_SSC
->SSC_SR
& (AT91C_SSC_RXRDY
)) {
627 b
= (int8_t)AT91C_BASE_SSC
->SSC_RHR
;
629 // The samples are correlations against I and Q versions of the
630 // tone that the tag AM-modulates, so every other sample is I,
631 // every other is Q. We just want power, so abs(I) + abs(Q) is
632 // close to what we want.
634 dest
[c
++] = (uint8_t) ABS(b
) + ABS(prev
);
646 Dbprintf("fin record");
650 // Initialize the proxmark as iso15k reader
651 // (this might produces glitches that confuse some tags
652 void Iso15693InitReader() {
658 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
662 // Start from off (no field generated)
663 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
666 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
669 // Give the tags time to energize
670 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
679 ///////////////////////////////////////////////////////////////////////
680 // ISO 15693 Part 3 - Air Interface
681 // This section basicly contains transmission and receiving of bits
682 ///////////////////////////////////////////////////////////////////////
684 // Encode (into the ToSend buffers) an identify request, which is the first
685 // thing that you must send to a tag to get a response.
686 static void BuildIdentifyRequest(void)
688 uint8_t cmd
[5] = {0,1,0,0,0};
690 // one sub-carrier, inventory, 1 slot, fast rate
691 // AFI is at bit 5 (1<<4) when doing an INVENTORY
692 cmd
[0] = (1 << 2) | (1 << 5) | (1 << 1);
693 // inventory command code
702 CodeIso15693AsReader(cmd
, sizeof(cmd
));
705 // uid is in transmission order (which is reverse of display order)
706 static void BuildReadBlockRequest(uint8_t *uid
, uint8_t blockNumber
)
708 uint8_t cmd
[13] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
710 // If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
711 // followed by teh block data
712 // one sub-carrier, inventory, 1 slot, fast rate
713 cmd
[0] = (1 << 6)| (1 << 5) | (1 << 1); // no SELECT bit, ADDR bit, OPTION bit
714 // READ BLOCK command code
716 // UID may be optionally specified here
725 cmd
[9] = uid
[7]; // 0xe0; // always e0 (not exactly unique)
726 // Block number to read
727 cmd
[10] = blockNumber
;//0x00;
729 crc
= Crc(cmd
, 11); // the crc needs to be calculated over 12 bytes
730 cmd
[11] = crc
& 0xff;
733 CodeIso15693AsReader(cmd
, sizeof(cmd
));
736 // Now the VICC>VCD responses when we are simulating a tag
737 static void BuildInventoryResponse( uint8_t *uid
)
739 uint8_t cmd
[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
741 // one sub-carrier, inventory, 1 slot, fast rate
742 // AFI is at bit 5 (1<<4) when doing an INVENTORY
743 //(1 << 2) | (1 << 5) | (1 << 1);
745 cmd
[1] = 0; // DSFID (data storage format identifier). 0x00 = not supported
747 cmd
[2] = uid
[7]; //0x32;
748 cmd
[3] = uid
[6]; //0x4b;
749 cmd
[4] = uid
[5]; //0x03;
750 cmd
[5] = uid
[4]; //0x01;
751 cmd
[6] = uid
[3]; //0x00;
752 cmd
[7] = uid
[2]; //0x10;
753 cmd
[8] = uid
[1]; //0x05;
754 cmd
[9] = uid
[0]; //0xe0;
757 cmd
[10] = crc
& 0xff;
760 CodeIso15693AsReader(cmd
, sizeof(cmd
));
763 // Universal Method for sending to and recv bytes from a tag
764 // init ... should we initialize the reader?
765 // speed ... 0 low speed, 1 hi speed
766 // **recv will return you a pointer to the received data
767 // If you do not need the answer use NULL for *recv[]
768 // return: lenght of received data
769 int SendDataTag(uint8_t *send
, int sendlen
, int init
, int speed
, uint8_t **recv
) {
771 int samples
= 0, tsamples
= 0;
772 int wait
= 0, elapsed
= 0;
775 LED_A_ON(); LED_B_ON();
777 LED_C_OFF(); LED_D_OFF();
779 if (init
) Iso15693InitReader();
781 // answer is 100bytes long?
782 uint8_t *answer
= BigBuf_malloc(100);
783 if (recv
!= NULL
) memset(answer
, 0, 100);
786 // low speed (1 out of 256)
787 CodeIso15693AsReader256(send
, sendlen
);
789 // high speed (1 out of 4)
790 CodeIso15693AsReader(send
, sendlen
);
796 TransmitTo15693Tag(ToSend
, ToSendMax
, &tsamples
, &wait
);
797 // Now wait for a response
801 answerLen
= GetIso15693AnswerFromTag(answer
, 100, &samples
, &elapsed
) ;
810 // --------------------------------------------------------------------
812 // --------------------------------------------------------------------
814 // Decodes a message from a tag and displays its metadata and content
815 #define DBD15STATLEN 48
816 void DbdecodeIso15693Answer(int len
, uint8_t *d
) {
817 char status
[DBD15STATLEN
+1] = {0};
821 if (d
[0] & ( 1 << 3 ))
822 strncat(status
, "ProtExt ", DBD15STATLEN
);
825 strncat(status
, "Error ", DBD15STATLEN
);
828 strncat(status
, "01:notSupp", DBD15STATLEN
);
831 strncat(status
, "02:notRecog", DBD15STATLEN
);
834 strncat(status
, "03:optNotSupp", DBD15STATLEN
);
837 strncat(status
, "0f:noInfo", DBD15STATLEN
);
840 strncat(status
, "10:dontExist", DBD15STATLEN
);
843 strncat(status
, "11:lockAgain", DBD15STATLEN
);
846 strncat(status
, "12:locked", DBD15STATLEN
);
849 strncat(status
, "13:progErr", DBD15STATLEN
);
852 strncat(status
, "14:lockErr", DBD15STATLEN
);
855 strncat(status
, "unknownErr", DBD15STATLEN
);
857 strncat(status
," " ,DBD15STATLEN
);
859 strncat(status
,"NoErr ", DBD15STATLEN
);
863 if ( (( crc
& 0xff ) == d
[len
-2]) && (( crc
>> 8 ) == d
[len
-1]) )
864 strncat(status
, "CrcOK", DBD15STATLEN
);
866 strncat(status
, "CrcFail!", DBD15STATLEN
);
868 Dbprintf("%s", status
);
872 ///////////////////////////////////////////////////////////////////////
873 // Functions called via USB/Client
874 ///////////////////////////////////////////////////////////////////////
876 void SetDebugIso15693(uint32_t debug
) {
878 Dbprintf("Iso15693 Debug is now %s", DEBUG
? "on" : "off");
882 //-----------------------------------------------------------------------------
883 // Simulate an ISO15693 reader, perform anti-collision and then attempt to read a sector
884 // all demodulation performed in arm rather than host. - greg
885 //-----------------------------------------------------------------------------
886 void ReaderIso15693(uint32_t parameter
)
901 uint8_t TagUID
[8] = {0x00};
903 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
905 uint8_t *answer1
= BigBuf_malloc(100);
906 uint8_t *answer2
= BigBuf_malloc(100);
907 uint8_t *answer3
= BigBuf_malloc(100);
909 memset(answer1
, 0x00, 100);
910 memset(answer2
, 0x00, 100);
911 memset(answer3
, 0x00, 100);
913 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
917 // Start from off (no field generated)
918 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
921 // Give the tags time to energize
922 FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
);
930 // FIRST WE RUN AN INVENTORY TO GET THE TAG UID
931 // THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME
933 // Now send the IDENTIFY command
934 BuildIdentifyRequest();
936 TransmitTo15693Tag(ToSend
,ToSendMax
,&tsamples
, &wait
);
938 // Now wait for a response
939 answerLen1
= GetIso15693AnswerFromTag(answer1
, 100, &samples
, &elapsed
) ;
941 if (answerLen1
>= 12) // we should do a better check than this
943 TagUID
[0] = answer1
[2];
944 TagUID
[1] = answer1
[3];
945 TagUID
[2] = answer1
[4];
946 TagUID
[3] = answer1
[5];
947 TagUID
[4] = answer1
[6];
948 TagUID
[5] = answer1
[7];
949 TagUID
[6] = answer1
[8]; // IC Manufacturer code
950 TagUID
[7] = answer1
[9]; // always E0
954 Dbprintf("%d octets read from IDENTIFY request:", answerLen1
);
955 DbdecodeIso15693Answer(answerLen1
, answer1
);
956 Dbhexdump(answerLen1
, answer1
, true);
960 Dbprintf("UID = %02hX%02hX%02hX%02hX%02hX%02hX%02hX%02hX",
961 TagUID
[7],TagUID
[6],TagUID
[5],TagUID
[4],
962 TagUID
[3],TagUID
[2],TagUID
[1],TagUID
[0]);
965 Dbprintf("%d octets read from SELECT request:", answerLen2
);
966 DbdecodeIso15693Answer(answerLen2
, answer2
);
967 Dbhexdump(answerLen2
, answer2
, true);
969 Dbprintf("%d octets read from XXX request:", answerLen3
);
970 DbdecodeIso15693Answer(answerLen3
,answer3
);
971 Dbhexdump(answerLen3
, answer3
, true);
974 if (answerLen1
>= 12 && DEBUG
) {
976 while ( i
< 32 ) { // sanity check, assume max 32 pages
977 BuildReadBlockRequest(TagUID
,i
);
978 TransmitTo15693Tag(ToSend
,ToSendMax
,&tsamples
, &wait
);
979 answerLen2
= GetIso15693AnswerFromTag(answer2
, 100, &samples
, &elapsed
);
981 Dbprintf("READ SINGLE BLOCK %d returned %d octets:", i
, answerLen2
);
982 DbdecodeIso15693Answer(answerLen2
, answer2
);
983 Dbhexdump(answerLen2
, answer2
, true);
984 if ( *((uint32_t*) answer2
) == 0x07160101 ) break; // exit on NoPageErr
996 // Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands
997 // all demodulation performed in arm rather than host. - greg
998 void SimTagIso15693(uint32_t parameter
, uint8_t *uid
)
1011 FpgaDownloadAndGo(FPGA_BITSTREAM_HF
);
1013 uint8_t *buf
= BigBuf_malloc(100);
1014 memset(buf
, 0x00, 100);
1016 SetAdcMuxFor(GPIO_MUXSEL_HIPKD
);
1019 // Start from off (no field generated)
1020 FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF
);
1029 answerLen1
= GetIso15693AnswerFromSniff(buf
, 100, &samples
, &elapsed
) ;
1031 if (answerLen1
>=1) // we should do a better check than this
1033 // Build a suitable reponse to the reader INVENTORY cocmmand
1034 // not so obsvious, but in the call to BuildInventoryResponse, the command is copied to the global ToSend buffer used below.
1036 BuildInventoryResponse(uid
);
1038 TransmitTo15693Reader(ToSend
,ToSendMax
, &tsamples
, &wait
);
1041 Dbprintf("%d octets read from reader command: %x %x %x %x %x %x %x %x %x", answerLen1
,
1042 buf
[0], buf
[1], buf
[2], buf
[3],
1043 buf
[4], buf
[5], buf
[6], buf
[7], buf
[8]);
1045 Dbprintf("Simulationg uid: %x %x %x %x %x %x %x %x",
1046 uid
[0], uid
[1], uid
[2], uid
[3],
1047 uid
[4], uid
[5], uid
[6], uid
[7]);
1056 // Since there is no standardized way of reading the AFI out of a tag, we will brute force it
1057 // (some manufactures offer a way to read the AFI, though)
1058 void BruteforceIso15693Afi(uint32_t speed
)
1061 uint8_t *recv
= data
;
1062 int datalen
= 0, recvlen
= 0;
1064 memset(data
, 0, sizeof(data
));
1066 Iso15693InitReader();
1068 // first without AFI
1069 // Tags should respond wihtout AFI and with AFI=0 even when AFI is active
1071 data
[0] = ISO15_REQ_SUBCARRIER_SINGLE
| ISO15_REQ_DATARATE_HIGH
|
1072 ISO15_REQ_INVENTORY
| ISO15_REQINV_SLOT1
;
1073 data
[1] = ISO15_CMD_INVENTORY
;
1074 data
[2] = 0; // mask length
1075 datalen
= AddCrc(data
, 3);
1076 recvlen
= SendDataTag(data
, datalen
, 0, speed
, &recv
);
1078 if (recvlen
>= 12) {
1079 Dbprintf("NoAFI UID=%s", sprintUID(NULL
, &recv
[2]));
1084 data
[0] = ISO15_REQ_SUBCARRIER_SINGLE
| ISO15_REQ_DATARATE_HIGH
|
1085 ISO15_REQ_INVENTORY
| ISO15_REQINV_AFI
| ISO15_REQINV_SLOT1
;
1086 data
[1] = ISO15_CMD_INVENTORY
;
1088 data
[3] = 0; // mask length
1090 for (int i
= 0; i
< 256; i
++) {
1091 data
[2] = i
& 0xFF; // iceman 2016, is & 0xFF needed?
1092 datalen
= AddCrc(data
, 4);
1093 recvlen
= SendDataTag(data
, datalen
, 0, speed
, &recv
);
1095 if (recvlen
>= 12) {
1096 Dbprintf("AFI=%i UID=%s", i
, sprintUID(NULL
, &recv
[2]));
1099 Dbprintf("AFI Bruteforcing done.");
1102 // Allows to directly send commands to the tag via the client
1103 void DirectTag15693Command(uint32_t datalen
,uint32_t speed
, uint32_t recv
, uint8_t data
[]) {
1106 uint8_t *recvbuf
= BigBuf_get_addr();
1110 Dbhexdump(datalen
,data
,true);
1113 recvlen
= SendDataTag(data
, datalen
, 1, speed
, (recv
? &recvbuf
: NULL
));
1117 cmd_send(CMD_ACK
,recvlen
>48?48:recvlen
,0,0,recvbuf
,48);
1122 DbdecodeIso15693Answer(recvlen
,recvbuf
);
1123 Dbhexdump(recvlen
,recvbuf
,true);