ADD: added a HF MFU INFO commmand, where you can see some tag info. Used to be in the readcard command.
FIX: minor code clean up for ultralight & desfire commands in armsrc/mifarecmd.c, armsrc/mifaredesfire.c, armsrc/mifareutil.c
CHG: Lowered the default MF_DBGLEVEL, it set to MF_DBG_ERROR.
CHG: lowered a testing value for timeout in cmdhf14a.c
void MifareUC_Auth1(uint8_t arg0, uint8_t *datain){\r
// variables\r
byte_t isOK = 0;\r
- byte_t dataoutbuf[16];\r
- uint8_t uid[10];\r
+ byte_t dataoutbuf[16] = {0x00};\r
+ uint8_t uid[10] = {0x00};\r
uint32_t cuid;\r
\r
// clear trace\r
\r
LED_B_ON();\r
cmd_send(CMD_ACK,isOK,cuid,0,dataoutbuf,11);\r
- LED_B_OFF();\r
\r
- // Thats it...\r
LEDsoff();\r
}\r
void MifareUC_Auth2(uint32_t arg0, uint8_t *datain){\r
- // params\r
+\r
uint32_t cuid = arg0;\r
- uint8_t key[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
- // variables\r
+ uint8_t key[16] = {0x00};\r
byte_t isOK = 0;\r
- byte_t dataoutbuf[16];\r
+ byte_t dataoutbuf[16] = {0x00};\r
\r
memcpy(key, datain, 16);\r
\r
if(mifare_ultra_auth2(cuid, key, dataoutbuf)){\r
if (MF_DBGLEVEL >= 1) Dbprintf("Authentication part2: Fail..."); \r
}\r
- isOK=1;\r
+ isOK = 1;\r
if (MF_DBGLEVEL >= 2) DbpString("AUTH 2 FINISHED");\r
\r
LED_B_ON();\r
- cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,11);\r
+ cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,11);\r
LED_B_OFF();\r
\r
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
\r
// variables\r
byte_t isOK = 0;\r
- byte_t dataoutbuf[16];\r
- uint8_t uid[10];\r
+ byte_t dataoutbuf[16] = {0x00};\r
+ uint8_t uid[10] = {0x00};\r
uint32_t cuid;\r
\r
// clear trace\r
{\r
// params\r
uint8_t sectorNo = arg0;\r
- int Pages=arg1;\r
- int count_Pages=0;\r
- // variables\r
- byte_t isOK = 0;\r
- byte_t dataoutbuf[176];\r
- uint8_t uid[10];\r
+ int Pages = arg1;\r
+ int count_Pages = 0;\r
+ byte_t dataoutbuf[176] = {0x00};;\r
+ uint8_t uid[10] = {0x00};\r
uint32_t cuid;\r
\r
- // clear trace\r
iso14a_clear_trace();\r
-\r
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
\r
LED_A_ON();\r
LED_B_OFF();\r
LED_C_OFF();\r
- Dbprintf("Pages %d",Pages);\r
- while (true) {\r
- if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
- break;\r
- };\r
- for(int sec=0;sec<Pages;sec++){\r
- if(mifare_ultra_readblock(cuid, sectorNo * 4 + sec, dataoutbuf + 4 * sec)) {\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Read block %d error",sec);\r
- break;\r
- }else{\r
- count_Pages++;\r
- };\r
- }\r
- if(mifare_ultra_halt(cuid)) {\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");\r
- break;\r
- };\r
-\r
- isOK = 1;\r
- break;\r
- }\r
- Dbprintf("Pages read %d",count_Pages);\r
- if (MF_DBGLEVEL >= 2) DbpString("READ CARD FINISHED");\r
-\r
- LED_B_ON();\r
- if (Pages==16) cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,64);\r
- if (Pages==44 && count_Pages==16) cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,64);\r
- if (Pages==44 && count_Pages>16) cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,176);\r
- LED_B_OFF();\r
+ \r
+ if (MF_DBGLEVEL >= MF_DBG_ALL) \r
+ Dbprintf("Pages %d",Pages);\r
+ \r
+ if (!iso14443a_select_card(uid, NULL, &cuid)) {\r
+ if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
+ Dbprintf("Can't select card");\r
+ OnError();\r
+ return;\r
+ }\r
+ \r
+ for (int i = 0; i < Pages; i++){\r
+ if (mifare_ultra_readblock(cuid, sectorNo * 4 + i, dataoutbuf + 4 * i)) {\r
+ if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
+ Dbprintf("Read block %d error",i);\r
+ OnError();\r
+ return;\r
+ } else {\r
+ count_Pages++;\r
+ }\r
+ }\r
+ \r
+ if (mifare_ultra_halt(cuid)) {\r
+ if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
+ Dbprintf("Halt error");\r
+ OnError();\r
+ return;\r
+ }\r
+ \r
+ if (MF_DBGLEVEL >= MF_DBG_ALL) {\r
+ Dbprintf("Pages read %d",count_Pages);\r
+ DbpString("Read card finished");\r
+ }\r
\r
- // Thats it...\r
+ int len = 16*4; //64 bytes\r
+ \r
+ // Read a UL-C\r
+ if (Pages == 44 && count_Pages > 16) \r
+ len = 176;\r
+\r
+ cmd_send(CMD_ACK, 1, 0, 0, dataoutbuf, len);\r
+ \r
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
LEDsoff();\r
-\r
}\r
\r
\r
\r
void MifareUWriteBlock(uint8_t arg0, uint8_t *datain)\r
{\r
- // params\r
- uint8_t blockNo = arg0;\r
- byte_t blockdata[16];\r
+ // params\r
+ uint8_t blockNo = arg0;\r
+ byte_t blockdata[16] = {0x00};\r
\r
- memset(blockdata,'\0',16);\r
- memcpy(blockdata, datain,16);\r
- \r
- // variables\r
- byte_t isOK = 0;\r
- uint8_t uid[10];\r
- uint32_t cuid;\r
+ memcpy(blockdata, datain, 16);\r
+ \r
+ // variables\r
+ byte_t isOK = 0;\r
+ uint8_t uid[10] = {0x00};\r
+ uint32_t cuid;\r
\r
- // clear trace\r
- iso14a_clear_trace();\r
+ iso14a_clear_trace();\r
+ iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
\r
- iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
+ LED_A_ON();\r
+ LED_B_OFF();\r
+ LED_C_OFF();\r
\r
- LED_A_ON();\r
- LED_B_OFF();\r
- LED_C_OFF();\r
-\r
- while (true) {\r
- if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
- break;\r
- };\r
-\r
- if(mifare_ultra_writeblock(cuid, blockNo, blockdata)) {\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");\r
- break;\r
- };\r
-\r
- if(mifare_ultra_halt(cuid)) {\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");\r
- break;\r
- };\r
- \r
- isOK = 1;\r
- break;\r
- }\r
- \r
- if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");\r
+ while (true) {\r
+ if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
+ break;\r
+ };\r
\r
- LED_B_ON();\r
- cmd_send(CMD_ACK,isOK,0,0,0,0);\r
- LED_B_OFF();\r
+ if(mifare_ultra_writeblock(cuid, blockNo, blockdata)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");\r
+ break;\r
+ };\r
\r
+ if(mifare_ultra_halt(cuid)) {\r
+ if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");\r
+ break;\r
+ };\r
+ \r
+ isOK = 1;\r
+ break;\r
+ }\r
+ \r
+ if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");\r
\r
- // Thats it...\r
- FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
- LEDsoff();\r
-// iso14a_set_tracing(TRUE);\r
+ cmd_send(CMD_ACK,isOK,0,0,0,0);\r
+ FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
+ LEDsoff();\r
}\r
\r
void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)\r
{\r
// params\r
uint8_t blockNo = arg0;\r
- byte_t blockdata[4];\r
+ byte_t blockdata[4] = {0x00};\r
\r
memcpy(blockdata, datain,4);\r
\r
// variables\r
byte_t isOK = 0;\r
- uint8_t uid[10];\r
+ uint8_t uid[10] = {0x00};\r
uint32_t cuid;\r
\r
- // clear trace\r
iso14a_clear_trace();\r
-\r
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
\r
LED_A_ON();\r
\r
if (MF_DBGLEVEL >= 2) DbpString("WRITE BLOCK FINISHED");\r
\r
- LED_B_ON();\r
cmd_send(CMD_ACK,isOK,0,0,0,0);\r
- LED_B_OFF();\r
-\r
- // Thats it...\r
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
LEDsoff();\r
}\r
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){\r
// variables\r
byte_t isOK = 0;\r
- byte_t dataoutbuf[16];\r
- uint8_t uid[10];\r
+ byte_t dataout[11] = {0x00};\r
+ uint8_t uid[10] = {0x00};\r
uint32_t cuid;\r
\r
- // clear trace\r
iso14a_clear_trace();\r
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
- \r
- LED_A_ON();\r
- LED_B_OFF();\r
- LED_C_OFF();\r
- \r
\r
if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card, something went wrong before auth");\r
};\r
\r
- if(mifare_desfire_des_auth1(cuid, dataoutbuf)){\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Authentication part1: Fail."); \r
+ if(mifare_desfire_des_auth1(cuid, dataout)){\r
+ if (MF_DBGLEVEL >= 1) \r
+ Dbprintf("Authentication part1: Fail."); \r
}\r
\r
- isOK=1;\r
- if (MF_DBGLEVEL >= 2) DbpString("AUTH 1 FINISHED");\r
+ isOK = 1;\r
+ if (MF_DBGLEVEL >= 2) DbpString("AUTH 1 FINISHED");\r
\r
- LED_B_ON();\r
- cmd_send(CMD_ACK,isOK,cuid,0,dataoutbuf,11);\r
- LED_B_OFF();\r
- \r
- // Thats it...\r
- //FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
- LEDsoff();\r
+ cmd_send(CMD_ACK,isOK,cuid,0,dataout, sizeof(dataout));\r
}\r
\r
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain){\r
- // params\r
+\r
uint32_t cuid = arg0;\r
- uint8_t key[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
- // variables\r
+ uint8_t key[16] = {0x00};\r
byte_t isOK = 0;\r
- byte_t dataoutbuf[16];\r
+ byte_t dataout[12] = {0x00};\r
\r
memcpy(key, datain, 16);\r
- // clear trace\r
- //iso14a_clear_trace();\r
- //iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
- \r
+ \r
LED_A_ON();\r
LED_B_OFF();\r
LED_C_OFF();\r
-\r
-// Dbprintf("Sending %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",\r
-// key[0],key[1],key[2],key[3],key[4],key[5],key[6],key[7],key[8],\r
-// key[9],key[10],key[11],key[12],key[13],key[14],key[15]);\r
\r
- if(mifare_desfire_des_auth2(cuid, key, dataoutbuf)){\r
- if (MF_DBGLEVEL >= 1) Dbprintf("Authentication part2: Fail..."); \r
+ isOK = mifare_desfire_des_auth2(cuid, key, dataout);\r
+ \r
+ if(isOK){\r
+ if (MF_DBGLEVEL >= 2) \r
+ DbpString("AUTH 2 FINISHED");\r
+ cmd_send(CMD_ACK,isOK,0,0,dataout,sizeof(dataout));\r
}\r
- isOK=1;\r
- if (MF_DBGLEVEL >= 2) DbpString("AUTH 2 FINISHED");\r
- \r
- LED_B_ON();\r
- cmd_send(CMD_ACK,isOK,0,0,dataoutbuf,12);\r
- LED_B_OFF();\r
- \r
- // Thats it...\r
+ else {\r
+ if (MF_DBGLEVEL >= 2) \r
+ Dbprintf("Authentication part2: Failed"); \r
+ OnError();\r
+ }\r
+\r
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
LEDsoff();\r
}
\ No newline at end of file
//static uint8_t __res[MAX_FRAME_SIZE];
bool InitDesfireCard(){
-
- // Make sure it is off.
-// FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
-// SpinDelay(300);
- byte_t cardbuf[USB_CMD_DATA_SIZE];
- memset(cardbuf,0,sizeof(cardbuf));
+ byte_t cardbuf[USB_CMD_DATA_SIZE] = {0x00};
+
iso14a_card_select_t *card = (iso14a_card_select_t*)cardbuf;
iso14a_set_tracing(TRUE);
void MifareDesfireGetInformation(){
int len = 0;
- uint8_t resp[USB_CMD_DATA_SIZE];
- uint8_t dataout[USB_CMD_DATA_SIZE];
- byte_t cardbuf[USB_CMD_DATA_SIZE];
-
- memset(resp,0,sizeof(resp));
- memset(dataout,0, sizeof(dataout));
- memset(cardbuf,0,sizeof(cardbuf));
+ uint8_t resp[USB_CMD_DATA_SIZE] = {0x00};
+ uint8_t dataout[USB_CMD_DATA_SIZE] = {0x00};
+ byte_t cardbuf[USB_CMD_DATA_SIZE] = {0x00};
/*
1 = PCB 1
//uint8_t new_key_data8[8] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77};
//uint8_t new_key_data16[16] = { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF};
- //uint8_t* bigbuffer = get_bigbufptr_recvrespbuf();
uint8_t resp[256] = {0x00};
uint8_t IV[16] = {0x00};
case 1:{
if (algo == 1) {
- uint8_t keybytes[8];
+ uint8_t keybytes[8] = {0x00};
uint8_t RndA[8] = {0x00};
uint8_t RndB[8] = {0x00};
for (int x = 0; x < 8; x++) {
decRndB[x] = decRndB[x] ^ encRndA[x];
-
}
des_dec(&encRndB, &decRndB, key->data);
case 3:{
//defaultkey
- uint8_t keybytes[16];
+ uint8_t keybytes[16] = {0x00};
if (datain[1] == 0xff){
memcpy(keybytes,PICC_MASTER_KEY16,16);
} else{
memcpy(keybytes, datain+1, datalen);
}
- struct desfire_key defaultkey = {0};
+ struct desfire_key defaultkey = {0x00};
desfirekey_t key = &defaultkey;
Desfire_aes_key_new( keybytes, key);
#include "crapto1.h"\r
#include "mifareutil.h"\r
\r
-int MF_DBGLEVEL = MF_DBG_ALL;\r
+int MF_DBGLEVEL = MF_DBG_ERROR;\r
\r
// memory management\r
uint8_t* get_bigbufptr_recvrespbuf(void) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("halt error. response len: %x", len);
return 1;
}
-
+\r
return 0;
}
int len = ReaderReceive(answer, answer_parity);\r
if(!len) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout.");\r
- return 2;\r
+ return 1;\r
}\r
return len;\r
}\r
int len = ReaderReceive(answer, answer_parity);\r
if(!len){\r
if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout.");\r
- return 2;\r
+ return 1;\r
}\r
return len;\r
}\r
int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData){\r
// variables\r
int len;\r
- // load key, keynumber\r
+ // load key, keynumber\r
uint8_t data[2]={0x0a, 0x00};\r
uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData){\r
// variables\r
int len;\r
- uint8_t data[17]={0xaf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+ uint8_t data[17] = {0x00};\r
+ data[0] = 0xAF;\r
memcpy(data+1,key,16);\r
\r
uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
// command MIFARE_CLASSIC_READBLOCK\r
len = mifare_sendcmd_special2(NULL, 1, 0x03, data, receivedAnswer, receivedAnswerPar ,NULL);\r
\r
- if ((receivedAnswer[0] == 0x03)&&(receivedAnswer[1] == 0xae)) {\r
+ if ((receivedAnswer[0] == 0x03) && (receivedAnswer[1] == 0xae)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Auth Error: %02x %02x", receivedAnswer[0], receivedAnswer[1]);\r
return 1;\r
}\r
UsbCommand resp;
char *hexout;
- if (WaitForResponseTimeout(CMD_ACK,&resp,10000)) {
+ if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
recv = resp.d.asBytes;
uint8_t iLen = iSelect ? resp.arg[1] : resp.arg[0];
PrintAndLog("received %i octets",iLen);
{"help", CmdHelp, 1, "This help"},\r
{"dbg", CmdHF14AMfDbg, 0, "Set default debug mode"},\r
{"rdbl", CmdHF14AMfRdBl, 0, "Read MIFARE classic block"},\r
- //{"urdbl", CmdHF14AMfURdBl, 0, "Read MIFARE Ultralight block"},\r
- //{"urdcard", CmdHF14AMfURdCard, 0,"Read MIFARE Ultralight Card"},\r
- //{"uwrbl", CmdHF14AMfUWrBl, 0,"Write MIFARE Ultralight block"},\r
{"rdsc", CmdHF14AMfRdSc, 0, "Read MIFARE classic sector"},\r
{"dump", CmdHF14AMfDump, 0, "Dump MIFARE classic tag to binary file"},\r
{"restore", CmdHF14AMfRestore, 0, "Restore MIFARE classic binary file to BLANK tag"},\r
{"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},\r
{"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},\r
{"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},\r
- {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block into magic Chinese card"},\r
- {"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block from magic Chinese card"},\r
- {"cgetsc", CmdHF14AMfCGetSc, 0, "Read sector from magic Chinese card"},\r
+ {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block - Magic Chinese card"},\r
+ {"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block - Magic Chinese card"},\r
+ {"cgetsc", CmdHF14AMfCGetSc, 0, "Read sector - Magic Chinese card"},\r
{"cload", CmdHF14AMfCLoad, 0, "Load dump into magic Chinese card"},\r
{"csave", CmdHF14AMfCSave, 0, "Save dump from magic Chinese card into file or emulator"},\r
{NULL, NULL, 0, NULL}\r
static int CmdHelp(const char *Cmd);
+int CmdHF14AMfUInfo(const char *Cmd){
+
+ uint8_t datatemp[7] = {0x00};
+ uint8_t isOK = 0;
+ uint8_t *data = NULL;
+
+ UsbCommand c = {CMD_MIFAREU_READCARD, {0, 4}};
+ SendCommand(&c);
+ UsbCommand resp;
+
+ if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
+ isOK = resp.arg[0] & 0xff;
+ data = resp.d.asBytes;
+
+ if (!isOK) {
+ PrintAndLog("Error reading from tag");
+ return -1;
+ }
+ } else {
+ PrintAndLog("Command execute timed out");
+ return -1;
+ }
+
+ // UID
+ memcpy( datatemp, data,3);
+ memcpy( datatemp+3, data+4, 4);
+ PrintAndLog(" UID :%s ", sprint_hex(datatemp, 7));
+ // BBC
+ // CT (cascade tag byte) 0x88 xor SN0 xor SN1 xor SN2
+ int crc0 = 0x88 ^ data[0] ^ data[1] ^data[2];
+ if ( data[3] == crc0 )
+ PrintAndLog(" BCC0 :%02x - Ok", data[3]);
+ else
+ PrintAndLog(" BCC0 :%02x - crc should be %02x", data[3], crc0);
+
+ int crc1 = data[4] ^ data[5] ^ data[6] ^data[7];
+ if ( data[8] == crc1 )
+ PrintAndLog(" BCC1 :%02x - Ok", data[8]);
+ else
+ PrintAndLog(" BCC1 :%02x - crc should be %02x", data[8], crc1 );
+
+ PrintAndLog(" Internal :%s ", sprint_hex(data + 9, 1));
+
+ memcpy(datatemp, data+10, 2);
+ PrintAndLog(" Lock :%s - %s", sprint_hex(datatemp, 2),printBits( 2, &datatemp) );
+ PrintAndLog(" OneTimePad :%s ", sprint_hex(data + 3*4, 4));
+ PrintAndLog("");
+
+ return 0;
+}
+
//
// Mifare Ultralight Write Single Block
//
int CmdHF14AMfURdCard(const char *Cmd){
int i;
uint8_t BlockNo = 0;
- int pages=16;
- uint8_t *lockbytes_t=NULL;
- uint8_t lockbytes[2]={0x00};
- bool bit[16]={0x00};
- bool dump=false;
- uint8_t datatemp[7]= {0x00};
-
+ int pages = 16;
+ uint8_t *lockbytes_t = NULL;
+ uint8_t lockbytes[2] = {0x00};
+ bool bit[16] = {0x00};
+ bool dump = false;
+ uint8_t datatemp[7] = {0x00};
uint8_t isOK = 0;
uint8_t * data = NULL;
FILE *fout = NULL;
if (strchr(Cmd,'x') != 0){
- dump=true;
+ dump = true;
if ((fout = fopen("dump_ultralight_data.bin","wb")) == NULL) {
PrintAndLog("Could not create file name dumpdata.bin");
return 1;
data = resp.d.asBytes;
PrintAndLog("isOk:%02x", isOK);
if (isOK) {
-
- // UID
- memcpy( datatemp, data,3);
- memcpy( datatemp+3, data+4, 4);
- PrintAndLog(" UID :%s ", sprint_hex(datatemp, 7));
- // BBC
- // CT (cascade tag byte) 0x88 xor SN0 xor SN1 xor SN2
- int crc0 = 0x88 ^ data[0] ^ data[1] ^data[2];
- if ( data[3] == crc0 ) {
- PrintAndLog(" BCC0 :%02x - Ok", data[3]);
- }
- else{
- PrintAndLog(" BCC0 :%02x - crc should be %02x", data[3], crc0);
- }
-
- int crc1 = data[4] ^ data[5] ^ data[6] ^data[7];
- if ( data[8] == crc1 ){
- PrintAndLog(" BCC1 :%02x - Ok", data[8]);
- }
- else{
- PrintAndLog(" BCC1 :%02x - crc should be %02x", data[8], crc1 );
- }
-
- PrintAndLog(" Internal :%s ", sprint_hex(data + 9, 1));
-
- memcpy(datatemp, data+10, 2);
- PrintAndLog(" Lock :%s - %s", sprint_hex(datatemp, 2),printBits( 2, &datatemp) );
-
- PrintAndLog(" OneTimePad :%s ", sprint_hex(data + 3*4, 4));
- PrintAndLog("");
for (i = 0; i < pages; i++) {
switch(i){
}
}
} else {
- PrintAndLog("Command1 execute timeout");
+ PrintAndLog("Command execute timeout");
}
if (dump) fclose(fout);
return 0;
//------------------------------------
static command_t CommandTable[] =
{
- {"help", CmdHelp, 1,"This help"},
- {"dbg", CmdHF14AMfDbg, 0,"Set default debug mode"},
- {"urdbl", CmdHF14AMfURdBl, 0,"Read MIFARE Ultralight block"},
- {"urdcard", CmdHF14AMfURdCard, 0,"Read MIFARE Ultralight Card"},
- {"udump", CmdHF14AMfUDump, 0,"Dump MIFARE Ultralight tag to binary file"},
- {"uwrbl", CmdHF14AMfUWrBl, 0,"Write MIFARE Ultralight block"},
- {"ucrdbl", CmdHF14AMfUCRdBl, 0,"Read MIFARE Ultralight C block"},
- {"ucrdcard",CmdHF14AMfUCRdCard, 0,"Read MIFARE Ultralight C Card"},
- {"ucdump", CmdHF14AMfUCDump, 0,"Dump MIFARE Ultralight C tag to binary file"},
- {"ucwrbl", CmdHF14AMfUCWrBl, 0,"Write MIFARE Ultralight C block"},
- {"auth", CmdHF14AMfucAuth, 0,"Ultralight C Authentication"},
+ {"help", CmdHelp, 1,"This help"},
+ {"dbg", CmdHF14AMfDbg, 0,"Set default debug mode"},
+ {"info", CmdHF14AMfUInfo, 0,"Taginfo"},
+ {"rdbl", CmdHF14AMfURdBl, 0,"Read block - MIFARE Ultralight"},
+ {"rdcard", CmdHF14AMfURdCard, 0,"Read card - MIFARE Ultralight"},
+ {"dump", CmdHF14AMfUDump, 0,"Dump MIFARE Ultralight tag to binary file"},
+ {"wrbl", CmdHF14AMfUWrBl, 0,"Write block - MIFARE Ultralight"},
+ {"crdbl", CmdHF14AMfUCRdBl, 0,"Read block - MIFARE Ultralight C"},
+ {"crdcard", CmdHF14AMfUCRdCard, 0,"Read card - MIFARE Ultralight C"},
+ {"cdump", CmdHF14AMfUCDump, 0,"Dump MIFARE Ultralight C tag to binary file"},
+ {"cwrbl", CmdHF14AMfUCWrBl, 0,"Write MIFARE Ultralight C block"},
+ {"cauth", CmdHF14AMfucAuth, 0,"try a Ultralight C Authentication"},
{NULL, NULL, 0, NULL}
};
#include "cmdhfmf.h"
+
//standard ultralight
int CmdHF14AMfUWrBl(const char *Cmd);
int CmdHF14AMfURdBl(const char *Cmd);
//general stuff
int CmdHFMFUltra(const char *Cmd);
+int CmdHF14AMfUInfo(const char *Cmd)