Updated to remove bugs

- For cards that aren’t magic, system will refuse to attempt writing
to block 0  / 1

 - Tested on Gen 1 & Gen 2 cards:

Gen 1
$ ./nfc-mfultralight w ul-test.dmp --full
NFC device: SCM Micro / SCL3711-NFC&RW opened
Found MIFARE Ultralight card with UID: 044e075ad42184
Writing 16 pages |................|
Done, 16 of 16 pages written (0 pages skipped).

Gen 2
$ ./nfc-mfultralight w ul-test.dmp --full
NFC device: SCM Micro / SCL3711-NFC&RW opened
Found MIFARE Ultralight card with UID: 044e075ad42184
Writing 16 pages |................|
Done, 16 of 16 pages written (0 pages skipped).

Non-magic
$ ./nfc-mfultralight w ul-test.dmp --full
NFC device: SCM Micro / SCL3711-NFC&RW opened
Found MIFARE Ultralight card with UID: 044e075ad42184
Writing 16 pages |
Unable to unlock card - are you sure the card is magic?
$
This commit is contained in:
Simon Yorkston 2016-04-09 03:42:01 +10:00
parent 8de7ce3899
commit e37de54e18

View file

@ -158,11 +158,9 @@ unlock_card(void)
transmit_bytes(abtHalt, 4);
// now send unlock
if (!transmit_bits(abtUnlock1, 7)) {
printf("unlock failure!\n");
return false;
}
if (!transmit_bytes(abtUnlock2, 1)) {
printf("unlock failure!\n");
return false;
}
@ -184,12 +182,6 @@ static bool check_magic() {
bool bFailure = false;
int uid_data;
//Initially check if we can unlock via the MF method
if (unlock_card()) {
printf("Ultralight Magic Gen 2 Detected\n");
return true;
}
for (uint32_t page = 0; page <= 1; page++) {
// Show if the readout went well
if (bFailure) {
@ -213,15 +205,24 @@ static bool check_magic() {
//Check that the ID is now set to 0x000000000000
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
//printf("%u", mp.mpd.abtData);
bool result = true;
for(int i = 0; i <= 7; i++) {
if (mp.mpd.abtData[i] != 0x00) return false;
if (mp.mpd.abtData[i] != 0x00) result = false;
}
if (result) {
return true;
}
}
//Initially check if we can unlock via the MF method
if (unlock_card()) {
return true;
} else {
return false;
return false;
}
printf("Ultralight Magic Gen 1 Detected\n");
return true;
}
static bool
@ -264,7 +265,11 @@ write_card(bool write_otp, bool write_lock, bool write_uid)
printf("ss");
uiSkippedPages = 2;
} else {
unlock_card();
if (!check_magic()) {
printf("\nUnable to unlock card - are you sure the card is magic?\n");
return false;
bFailure = false;
}
}
for (int page = uiSkippedPages; page <= 0xF; page++) {