+\r
+//-----------------------------------------------------------------------------\r
+// MIFARE Personalize UID. Only for Mifare Classic EV1 7Byte UID\r
+//-----------------------------------------------------------------------------\r
+void MifarePersonalizeUID(uint8_t keyType, uint8_t perso_option, uint8_t *data) {\r
+\r
+ uint8_t uid[10];\r
+ uint32_t cuid;\r
+ struct Crypto1State mpcs = {0, 0};\r
+ struct Crypto1State *pcs;\r
+ pcs = &mpcs;\r
+\r
+ LED_A_ON();\r
+ clear_trace();\r
+\r
+ iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
+\r
+ bool isOK = false;\r
+ while (true) {\r
+ if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
+ break;\r
+ }\r
+\r
+ uint8_t block_number = 0;\r
+ uint64_t key = bytes_to_num(data, 6);\r
+ if (mifare_classic_auth(pcs, cuid, block_number, keyType, key, AUTH_FIRST)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Auth error");\r
+ break;\r
+ }\r
+\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
+ int len = mifare_sendcmd_short(pcs, true, MIFARE_EV1_PERSONAL_UID, perso_option, receivedAnswer, receivedAnswerPar, NULL);\r
+ if (len != 1 || receivedAnswer[0] != CARD_ACK) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Cmd Error: %02x", receivedAnswer[0]);\r
+ break;;\r
+ }\r
+ isOK = true;\r
+ break;\r
+ }\r
+\r
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+ LED_D_OFF();\r
+\r
+ crypto1_destroy(pcs);\r
+\r
+ if (MF_DBGLEVEL >= 2) DbpString("PERSONALIZE UID FINISHED");\r
+\r
+ cmd_send(CMD_ACK, isOK, 0, 0, NULL, 0);\r
+\r
+ LED_A_OFF();\r
+}\r
+\r