Guest User

Untitled

a guest
Apr 13th, 2017
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Typical pin layout used:
  3. -----------------------------------------------------------------------------------------
  4. MFRC522 Arduino Arduino Arduino Arduino Arduino
  5. Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro
  6. Signal Pin Pin Pin Pin Pin Pin
  7. -----------------------------------------------------------------------------------------
  8. RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
  9. SPI SS SDA(SS) 10 53 D10 10 10
  10. SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
  11. SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
  12. SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
  13. */
  14.  
  15. #include <SPI.h>
  16. #include <MFRC522.h>
  17.  
  18. #define RST_PIN 9 // Configurable, see typical pin layout above
  19. #define SS_PIN 10 // Configurable, see typical pin layout above
  20.  
  21. MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
  22.  
  23.  
  24. void setup() {
  25. Serial.begin(9600); // Initialize serial communications with the PC
  26. while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  27. SPI.begin(); // Init SPI bus
  28. mfrc522.PCD_Init(); // Init MFRC522
  29. mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
  30. Serial.println(F("Arduino Amiibo writer. Put your NFC-tag to the reader"));
  31. }
  32.  
  33. void loop() {
  34. // Look for new cards
  35. if ( ! mfrc522.PICC_IsNewCardPresent()) {
  36. return;
  37. }
  38.  
  39. // Select one of the cards
  40. if ( ! mfrc522.PICC_ReadCardSerial()) {
  41. return;
  42. }
  43.  
  44. // hexdump -v -e " 4/1 \"0x%02X, \" \"\n\"" Chibi-Robo.encoded.bin
  45. byte pages = 135;
  46. byte dataBlock[] = {
  47.  
  48. 0x04, 0x7A, 0xC7, 0x31,
  49. 0x5A, 0x06, 0x4F, 0x81,
  50. 0x92, 0x48, 0x00, 0x00,
  51. 0xF1, 0x10, 0xFF, 0xEE,
  52. 0xA5, 0x00, 0x00, 0x00,
  53. 0x48, 0xF9, 0xEA, 0xC1,
  54. 0x1E, 0xA0, 0x01, 0x28,
  55. 0x59, 0x63, 0xFE, 0x77,
  56. 0x3B, 0x34, 0xF6, 0xD1,
  57. 0x3A, 0x6B, 0x40, 0xFE,
  58. 0x85, 0x7D, 0x03, 0xC4,
  59. 0xA4, 0xCC, 0x94, 0xA6,
  60. 0xA3, 0xB1, 0x8A, 0xBA,
  61. 0x68, 0x43, 0x53, 0xB8,
  62. 0xF0, 0x12, 0x29, 0x68,
  63. 0x59, 0x64, 0xB3, 0xAD,
  64. 0x12, 0xDA, 0x7F, 0x17,
  65. 0x93, 0x87, 0x08, 0x94,
  66. 0xC9, 0xD7, 0x27, 0xD3,
  67. 0x03, 0x01, 0xA5, 0x42,
  68. 0x5A, 0xC4, 0x21, 0xF6,
  69. 0x01, 0x00, 0x00, 0x00,
  70. 0x00, 0x04, 0x00, 0x02,
  71. 0x04, 0x12, 0x94, 0x0C,
  72. 0x0F, 0x91, 0xE1, 0xD5,
  73. 0xA0, 0xE1, 0xFC, 0xA7,
  74. 0x24, 0xB6, 0xCC, 0xE9,
  75. 0xC8, 0xE7, 0xFB, 0xE0,
  76. 0x8E, 0x40, 0xD2, 0x37,
  77. 0x13, 0x0F, 0xD2, 0xC6,
  78. 0xA5, 0x19, 0x23, 0x07,
  79. 0x16, 0xA2, 0xC7, 0xB6,
  80. 0xCB, 0xA5, 0xF8, 0x30,
  81. 0xDC, 0x0A, 0xBB, 0x97,
  82. 0x9E, 0xCE, 0x60, 0xD8,
  83. 0x43, 0xE2, 0xC1, 0x23,
  84. 0xB5, 0x82, 0xDB, 0xBD,
  85. 0x8F, 0x91, 0x71, 0x49,
  86. 0x5A, 0x13, 0x5B, 0xFF,
  87. 0xC2, 0x34, 0x8C, 0xA1,
  88. 0x3C, 0xCE, 0xB6, 0x25,
  89. 0xF8, 0xF3, 0x5C, 0xF2,
  90. 0x9F, 0xB0, 0xCD, 0x53,
  91. 0x93, 0x7F, 0xAC, 0x14,
  92. 0x4A, 0xE1, 0xA7, 0xC8,
  93. 0x74, 0x11, 0xA7, 0x45,
  94. 0x87, 0x96, 0x01, 0xE1,
  95. 0x70, 0x32, 0x69, 0xDF,
  96. 0x54, 0x83, 0xE5, 0xB5,
  97. 0x62, 0xA9, 0x39, 0x6A,
  98. 0xE7, 0xA2, 0x7C, 0x4F,
  99. 0x14, 0x1F, 0xDF, 0xA8,
  100. 0x13, 0xDE, 0xA9, 0x21,
  101. 0x18, 0x87, 0x7B, 0x4C,
  102. 0x18, 0x6C, 0x43, 0x75,
  103. 0x2C, 0xC9, 0x69, 0xB0,
  104. 0x68, 0xBD, 0xE6, 0xB3,
  105. 0xAB, 0x0F, 0xAB, 0x86,
  106. 0x9C, 0x92, 0xCA, 0xA4,
  107. 0xF9, 0x30, 0x1F, 0x91,
  108. 0xDD, 0x67, 0xD6, 0x5D,
  109. 0x49, 0x8A, 0x5C, 0xBC,
  110. 0xCB, 0xDB, 0xD2, 0x3E,
  111. 0x64, 0x30, 0x83, 0x5F,
  112. 0xC2, 0xB8, 0x2A, 0xB6,
  113. 0x51, 0x4E, 0xB9, 0x26,
  114. 0x4C, 0x32, 0x41, 0x9E,
  115. 0xA5, 0xA2, 0x46, 0x74,
  116. 0x92, 0x41, 0xAC, 0x36,
  117. 0xC8, 0x57, 0x6A, 0x4D,
  118. 0x50, 0x70, 0xFA, 0xB4,
  119. 0x88, 0xA8, 0xAF, 0x98,
  120. 0x68, 0x21, 0xEF, 0x61,
  121. 0x0D, 0x9E, 0x5D, 0x68,
  122. 0x88, 0x94, 0xC1, 0x46,
  123. 0x18, 0xC7, 0x6B, 0x50,
  124. 0x06, 0xF9, 0xAD, 0xD9,
  125. 0x73, 0xD9, 0x91, 0x1E,
  126. 0xDC, 0x5E, 0xC9, 0x05,
  127. 0xBE, 0xB0, 0xF3, 0x6E,
  128. 0xB3, 0x33, 0x44, 0xF1,
  129. 0x6C, 0xB4, 0x75, 0xA8,
  130. 0x71, 0x75, 0x55, 0xAF,
  131. 0x3D, 0x20, 0xE8, 0xDC,
  132. 0x8C, 0x4F, 0x96, 0x8B,
  133. 0xC1, 0x5A, 0x1E, 0x2D,
  134. 0xDE, 0xED, 0x41, 0x59,
  135. 0x04, 0x1F, 0x2D, 0x81,
  136. 0x08, 0x60, 0x67, 0x96,
  137. 0xD2, 0xBE, 0xC9, 0xAA,
  138. 0xBB, 0x55, 0x10, 0xC2,
  139. 0x84, 0x31, 0xC5, 0xBD,
  140. 0xBB, 0xB5, 0xBE, 0x85,
  141. 0xC0, 0xC4, 0xAF, 0x7A,
  142. 0x15, 0x23, 0xD6, 0xA5,
  143. 0x16, 0x09, 0xBB, 0x81,
  144. 0xAD, 0x79, 0x85, 0xFB,
  145. 0xD1, 0xFE, 0x6A, 0x51,
  146. 0xCF, 0xBA, 0x7E, 0x48,
  147. 0x55, 0x99, 0x53, 0x2B,
  148. 0x8D, 0x66, 0x90, 0xB0,
  149. 0x8E, 0x22, 0xD3, 0xA2,
  150. 0x66, 0x3C, 0x7F, 0xA1,
  151. 0xF1, 0x45, 0x12, 0x3B,
  152. 0x6D, 0x78, 0x6C, 0x8F,
  153. 0xAF, 0xBA, 0xA5, 0x7B,
  154. 0x31, 0xA5, 0x1D, 0x3F,
  155. 0xE5, 0x08, 0x20, 0x37,
  156. 0x1E, 0x3C, 0x94, 0x58,
  157. 0xD8, 0x12, 0x72, 0xDC,
  158. 0x61, 0x2B, 0xAA, 0xC7,
  159. 0xA2, 0x1B, 0x4B, 0x64,
  160. 0x30, 0x84, 0x65, 0x9F,
  161. 0xFE, 0xF9, 0x3C, 0x8E,
  162. 0x7B, 0xD7, 0xC1, 0x90,
  163. 0x19, 0x2B, 0x21, 0x9E,
  164. 0xDE, 0xFF, 0xD0, 0xC4,
  165. 0xAD, 0x47, 0x1F, 0x01,
  166. 0xA4, 0x4F, 0x71, 0x0B,
  167. 0x10, 0x8A, 0xC1, 0x3E,
  168. 0xF8, 0x51, 0xB2, 0xC2,
  169. 0x4A, 0x59, 0x7A, 0xC4,
  170. 0x12, 0x40, 0xC3, 0xB1,
  171. 0xC2, 0xFB, 0xED, 0x5E,
  172. 0x7F, 0xBE, 0x32, 0x62,
  173. 0xAD, 0xFB, 0x1F, 0xC0,
  174. 0xDE, 0x44, 0xB6, 0x88,
  175. 0x86, 0x92, 0x5B, 0x2C,
  176. 0x15, 0xA0, 0x11, 0x69,
  177. 0xF8, 0x53, 0x8C, 0x04,
  178. 0x00, 0x00, 0x00, 0xBD,
  179. 0x00, 0x00, 0x00, 0x04,
  180. 0x5F, 0x00, 0x00, 0x00,
  181. 0x8A, 0x94, 0xBF, 0xD2,
  182. 0x80, 0x80, 0x00, 0x00,
  183.  
  184. };
  185.  
  186. MFRC522::StatusCode status;
  187.  
  188. // Write main data
  189. for (byte page = 25; page < pages; page++) {
  190. // Write data to the page
  191. Serial.print(F("Writing data into page ")); Serial.print(page);
  192. Serial.println(F(" ..."));
  193. dump_byte_array(dataBlock + (page * 4), 4); Serial.println();
  194. status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(page, dataBlock + (page * 4), 4);
  195. if (status != MFRC522::STATUS_OK) {
  196. Serial.print(F("MIFARE_Write() failed: "));
  197. Serial.println(mfrc522.GetStatusCodeName(status));
  198. }
  199. Serial.println();
  200. }
  201.  
  202. // Write lock bytes - the last thing you should do.
  203. // If you write them too early - your tag is wasted.
  204. // Write the Dynamic Lock Bytes
  205. byte DynamicLockBlock[] = {
  206. 0x01, 0x00, 0x0F, 0xBD
  207. };
  208. Serial.print(F("Writing Dynamic Lock Bytes into page 130"));
  209. Serial.println(F(" ..."));
  210. dump_byte_array(DynamicLockBlock, 4); Serial.println();
  211. status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(130, DynamicLockBlock, 4);
  212. if (status != MFRC522::STATUS_OK) {
  213. Serial.print(F("MIFARE_Write() failed: "));
  214. Serial.println(mfrc522.GetStatusCodeName(status));
  215. }
  216. Serial.println();
  217.  
  218. // Now we can write Static Lock Bytes
  219. byte StaticLockBlock[] = {
  220. 0x0F, 0xE0, 0x0F, 0xE0
  221. };
  222. Serial.print(F("Writing Static Lock Bytes into page 2"));
  223. Serial.println(F(" ..."));
  224. dump_byte_array(StaticLockBlock, 4); Serial.println();
  225. status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(2, StaticLockBlock, 4);
  226. if (status != MFRC522::STATUS_OK) {
  227. Serial.print(F("MIFARE_Write() failed: "));
  228. Serial.println(mfrc522.GetStatusCodeName(status));
  229. }
  230. Serial.println();
  231.  
  232. // Halt PICC
  233. mfrc522.PICC_HaltA();
  234. // Stop encryption on PCD
  235. mfrc522.PCD_StopCrypto1();
  236.  
  237. Serial.println("Write finished! Now please take your Amiibo card away!");
  238. delay(30000);
  239. }
  240.  
  241. /**
  242. Helper routine to dump a byte array as hex values to Serial.
  243. */
  244.  
  245. void dump_byte_array(byte *buffer, byte bufferSize) {
  246. for (byte i = 0; i < bufferSize; i++) {
  247. Serial.print(buffer[i] < 0x10 ? " 0" : " ");
  248. Serial.print(buffer[i], HEX);
  249. }
  250. }
RAW Paste Data