+\r
+ if(!iso14443a_select_card(NULL, NULL, NULL)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
+ OnError(0);\r
+ return;\r
+ };\r
+\r
+ // UL-C authentication\r
+ if ( useKey ) {\r
+ uint8_t key[16] = {0x00};\r
+ memcpy(key, datain+4, sizeof(key) );\r
+\r
+ if ( !mifare_ultra_auth(key) ) {\r
+ OnError(1);\r
+ return;\r
+ }\r
+ }\r
+ \r
+ // UL-EV1 / NTAG authentication\r
+ if (usePwd) {\r
+ uint8_t pwd[4] = {0x00};\r
+ memcpy(pwd, datain+4, 4);\r
+ uint8_t pack[4] = {0,0,0,0};\r
+ if (!mifare_ul_ev1_auth(pwd, pack)) {\r
+ OnError(1);\r
+ return;\r
+ }\r
+ }\r
+\r
+ if(mifare_ultra_writeblock(blockNo, blockdata)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");\r
+ OnError(0);\r
+ return;\r
+ };\r
+\r
+ if(mifare_ultra_halt()) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");\r
+ OnError(0);\r
+ return;\r
+ };\r
+\r
+ if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");\r
+\r
+ cmd_send(CMD_ACK,1,0,0,0,0);\r
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+ LEDsoff();\r
+}\r
+\r
+void MifareUSetPwd(uint8_t arg0, uint8_t *datain){\r
+ \r
+ uint8_t pwd[16] = {0x00};\r
+ byte_t blockdata[4] = {0x00};\r
+ \r
+ memcpy(pwd, datain, 16);\r
+ \r
+ LED_A_ON(); LED_B_OFF(); LED_C_OFF();\r