-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0_reader.ino
116 lines (91 loc) · 2.79 KB
/
0_reader.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
@brief example of reading mf1s50 card for NFC_MODULE
For this demo, waiting for a MF1S50 card or tag, after reading a card/tag UID,
then try to read the block 4/5/6/7 ..
V1.0 initial version
*/
/** include library */
#include "nfc.h"
/** define a nfc class */
NFC_Module nfc;
void setup(void)
{
Serial.begin(9600);
nfc.begin();
Serial.println("NFC MF1S50 Reader!");
uint32_t versiondata = nfc.get_version();
/*if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}*/
// Affiche la version de la puce!
Serial.print("Puce PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
/** Set normal mode, and disable SAM */
nfc.SAMConfiguration();
}
void loop(void)
{
u8 buf[32],sta;
/** Polling the mifar card, buf[0] is the length of the UID */
sta = nfc.InListPassiveTarget(buf);
/** check state and UID length */
if(sta && buf[0] == 4){
/** the card may be Mifare Classic card, try to read the block */
Serial.println();
Serial.print("UUID length:");
Serial.print(buf[0], DEC);
Serial.println();
Serial.print("UUID:");
nfc.puthex(buf+1, buf[0]);
Serial.println();
/** factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF */
u8 key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
u8 blocknum = 4;
/** Authentication blok 4 */
sta = nfc.MifareAuthentication(0, blocknum, buf+1, buf[0], key);
if(sta){
/** save read block data */
u8 block[16];
Serial.println("Authentication success.");
// uncomment following lines for writing data to blok 4
/*
strcpy((char*)block, "Elechoues - NFC");
sta = nfc.MifareWriteBlock(blocknum, block);
if(sta){
Serial.println("Write block successfully:");
}
*/
/** read block 4 */
sta = nfc.MifareReadBlock(blocknum, block);
if(sta){
Serial.println("Read block 4 successfully:");
nfc.puthex(block, 16);
Serial.println();
}
/** read block 5 */
sta = nfc.MifareReadBlock(blocknum+1, block);
if(sta){
Serial.println("Read block 5 successfully:");
nfc.puthex(block, 16);
Serial.println();
}
/** read block 6 */
sta = nfc.MifareReadBlock(blocknum+2, block);
if(sta){
Serial.println("Read block 6 successfully:");
nfc.puthex(block, 16);
Serial.println();
}
/** read block 7 */
sta = nfc.MifareReadBlock(blocknum+3, block);
if(sta){
Serial.println("Read block 7 successfully:");
nfc.puthex(block, 16);
Serial.println();
}
delay(2000);
}
}
}