Commit e6ab6603 authored by Romuald Conty's avatar Romuald Conty

Better support for some special chinese cards

Fixes issue 190
parent c9582011
...@@ -67,6 +67,7 @@ static bool bUseKeyA; ...@@ -67,6 +67,7 @@ static bool bUseKeyA;
static bool bUseKeyFile; static bool bUseKeyFile;
static bool bForceKeyFile; static bool bForceKeyFile;
static bool bTolerateFailures; static bool bTolerateFailures;
static bool magic2 = false;
static uint8_t uiBlocks; static uint8_t uiBlocks;
static uint8_t keys[] = { static uint8_t keys[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
...@@ -223,7 +224,10 @@ authenticate(uint32_t uiBlock) ...@@ -223,7 +224,10 @@ authenticate(uint32_t uiBlock)
static bool static bool
unlock_card(void) unlock_card(void)
{ {
printf("Unlocking card\n"); if (magic2) {
printf("Don't use R/W with this card, this is not required!\n");
return false;
}
// Configure the CRC // Configure the CRC
if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) { if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) {
...@@ -405,7 +409,7 @@ write_card(int write_block_zero) ...@@ -405,7 +409,7 @@ write_card(int write_block_zero)
} }
} else { } else {
// The first block 0x00 is read only, skip this // The first block 0x00 is read only, skip this
if (uiBlock == 0 && ! write_block_zero) if (uiBlock == 0 && ! write_block_zero && ! magic2)
continue; continue;
...@@ -415,8 +419,9 @@ write_card(int write_block_zero) ...@@ -415,8 +419,9 @@ write_card(int write_block_zero)
memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData, 16); memcpy(mp.mpd.abtData, mtDump.amb[uiBlock].mbd.abtData, 16);
// do not write a block 0 with incorrect BCC - card will be made invalid! // do not write a block 0 with incorrect BCC - card will be made invalid!
if (uiBlock == 0) { if (uiBlock == 0) {
if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00) { if ((mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3] ^ mp.mpd.abtData[4]) != 0x00 && !magic2) {
printf("!\nError: incorrect BCC in MFD file!\n"); printf("!\nError: incorrect BCC in MFD file!\n");
printf("Expecting BCC=%02X\n", mp.mpd.abtData[0] ^ mp.mpd.abtData[1] ^ mp.mpd.abtData[2] ^ mp.mpd.abtData[3]);
return false; return false;
} }
} }
...@@ -600,6 +605,11 @@ main(int argc, const char *argv[]) ...@@ -600,6 +605,11 @@ main(int argc, const char *argv[])
// MIFARE Plus 2K // MIFARE Plus 2K
uiBlocks = 0x7f; uiBlocks = 0x7f;
} }
// Chinese magic emulation card, ATS=0978009102:dabc1910
if ((res == 9) && (abtRx[5] == 0xda) && (abtRx[6] == 0xbc)
&& (abtRx[7] == 0x19) && (abtRx[8] == 0x10)) {
magic2 = true;
}
} }
printf("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16); printf("Guessing size: seems to be a %i-byte card\n", (uiBlocks + 1) * 16);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment